pymongo基本使用

2017-11-13  本文已影响0人  NoFacePeace
import pymongo
import pymongo
client = pymongo.MongoClient()
db = conn.database
# 或
db = conn['database']
accout = db.collection
# 或
accout = db['collection']
db.collection_name()
db.collection.find_one()
db.collection.find_one({'userName' : 'keyword'})
db.collection.find_one({}, {'username':1,'email':1})
db.collection.find_one({},{'username':1,'email':1,"_id":0})
for item in db.collection.find():
    item
for item in db.collection.find({"username":"libing"}):
    item['username']
db.collection.find(),count()
db.collection.find({"username":"keyword"}).count()
db.collection.find().sort("username")
# 默认升序
db.collection.find().sort("username",pymongo.ASCENDING)
# 升序
db.collection.find().sort("username",pymongo.DESCENDING)
# 降序
db.collection.find().sort([("username",pymongo.ASCENDING),("Email",pymongo.DESCENDING)])
db.collection.insert({"accout":21,"username":"libing"})
db.collection.update({"username":"libing"},{"$set":{"email":"libing","password","123"}})
db.collection.remove()
db.collection.remove({"username":"keyword"})
上一篇下一篇

猜你喜欢

热点阅读