mongodb 1: 把玩把玩
这里对mongodb做一些初步认识
当然首先得启动服务和mongo shell
?
#查看
db.users.find()?????????????? #读取所有文档
db.users.findOne()??????? #读取一个文档?
#更新
user.address = "chengdu"
db.users.update({"name":"nico"}, user)
db.users.find()?
#删除
#删除文档
db.users.remove({"name":"aaa"})
db.users.remove()?
以上操作在pymongo中实现#!/usr/bin/env python# -*- coding: utf-8 -*-from pymongo import Connection#get a connectionconnection = Connection('localhost', 27017)#show all databasesprint connection.database_names()#instance a new dbdb = connection['sample']#get a collection --> tableusers = db.usersuser = {"name":"nico", "age":30, "gender":"male"}users.insert(user)#读取所有文档datas = users.find()for user in datas: print user#读取一个文档print users.find_one()#updateusers.update({"name":"nico"}, {"$set":{"address":"chengdu"}})print users.find_one()#remove documentusers.remove()??