>>> import pymongo
>>> conn = pymongo.Connection(‘localhost‘,27017)
import
>>> conn = Connection(‘localhost‘,27017)
>>> db.Account.find_one()
>>> db.Account.find_one({"UserName":"keyword"})
>>> db.Account.find_one({},{"UserName":1,"Email":1})
{u‘UserName‘: u‘libing‘, u‘_id‘: ObjectId(‘4ded95c3b7780a774a099b7c‘), u‘Email‘: u‘libing@35.cn‘}
>>> db.Account.find_one({},{"UserName":1,"Email":1,"_id":0})
{u‘UserName‘: u‘libing‘, u‘Email‘: u‘libing@35.cn‘}
>>> for item in db.Account.find():
item
>>> for item in db.Account.find({"UserName":"libing"}):
item["UserName"]
>>> db.Account.find().count()
>>> db.Account.find({"UserName":"keyword"}).count()
>>> db.Account.find().sort("UserName") --默认为升序
>>> db.Account.find().sort("UserName",pymongo.ASCENDING) --升序
>>> db.Account.find().sort("UserName",pymongo.DESCENDING) --降序
>>> db.Account.find().sort([("UserName",pymongo.ASCENDING),("Email",pymongo.DESCENDING)])
>>> db.Account.insert({"AccountID":21,"UserName":"libing"})
>>> db.Account.update({"UserName":"libing"},{"$set":{"Email":"libing@126.com","Password":"123"}})
>>> db.Account.remove() -- 全部删除
>>> db.Test.remove({"UserName":"keyword"})