Mongodb--Python使用mongodb

来源:互联网 发布:阿里云域名实名认证 编辑:程序博客网 时间:2024/05/29 03:20

1.安装pymongo

pip install pymongo

2.使用pymongo连接mongodb

In [1]: from pymongo import MongoClientIn [3]: client = MongoClient("localhost",27017)In [4]: db = client.testIn [5]: db.authenticate("testuser","Aa123456")In [6]: collection = db.mysetIn [7]: collection.insert_one(   ...: {"name":"zhangsan",   ...: "age":12,   ...: } )In [10]: collection.find_one()Out[10]: {'_id': ObjectId('59f120e4f4e4b1504796c700'), 'age': 12, 'name': 'zhangsan'}
原创粉丝点击