Python操作MongoDB
"""
操作mongodb数据库
"""
import pymongo
client = pymongo.MongoClient('mongodb://localhost:27017')
db_name = 'flask'
db = client[db_name]
collection = db['users']
def insert():
users = {"name": "xiassss", "age": "23"}
collection.insert(users)
collection.save(users)
def insert_many():
users=[{'name':'LIM','age':'55'},{'name':'MMM','age':'77'}]
for user in users:
collection.insert(user)
collection.save(user)
def select():
data=collection.find_one({'name':'LIM'})
print data
def remove():
collection.remove({'name':'MMM'})
def replace():
collection.replace_one({'name':'LIM'},{'name':'RRR'})