pymongoコード例(mongody)

1463 ワード

from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.dbsample

Insert

doc = {'name':'bobby','age':21}
db.users.insert_one(doc)

Find

user = db.users.find_one({'name':'bobby'})

Find list(id値を除く)

same_ages = list(db.users.find({'age':21},{'_id':False}))

update

db.users.update_one({'name':'bobby'},{'$set':{'age':19}})

update many

#db.users.update_many({'name':'bobby'},{'$set':{'age':19}})

delete

db.users.delete_one({'name':'bobby'})

delete many

#db.users.delete_many({'name':'bobby'})