
本文共 2195 字,大约阅读时间需要 7 分钟。
Python���MongoDB���������������������
������MongoDB���������
���������Python���MongoDB������������������������������������������MongoDB������������������������������������������������������������������������������������������������
net start MongoDB
���������������������MongoDB���������������������������������������������
������pymongo���
���Python���������pymongo������������������������pip���������������������������������������������
pip install pymongo
���������������������������������������pymongo���������MongoDB���������������
���������������MongoDB���������
������������
������������������pymongo���������������������
import pymongo
���������������������
���������������������Python������������MongoDB���������������������������������������������������������������������
client = pymongo.MongoClient('127.0.0.1', 27017)
������������������������
���������������������������������������������������������������������������
db = client['mymongo']collection = db['mymongo']
���������������������
������������
������������������
���������������������������������������������������find_one()
���������
data = collection.find_one()
������������������
������������������������������������������������find()
������������������������������������������
for document in collection.find(): print(document)
������������
������������������
������������������������������������������������������������insert_one()
���������
collection.insert_one({'_id': 1, 'name': '���������', '������': '���'})
������������������
������������������������������������������������������������insert_many()
���������
data = [ {'_id': 2, 'name': '������', '������': '���'}, {'_id': 3, 'name': '������', '������': '���'}]collection.insert_many(data)
������������
������������������
���������������������������������������������������delete_one()
���������
result = collection.delete_one({'_id': 1})
������������������
������������������������������������������������delete_many()
���������
result = collection.delete_many({'_id': {'$lt': 3}})
������������
������������������
���������������������������������������������������update_one()
���������
collection.update_one({'_id': 1}, {'$set': {'name': '������'}})
发表评论
最新留言
关于作者
