ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 与python交互 * 点击查看[官方文档](http://api.mongodb.com/python/current/tutorial.html) * 安装python包 ~~~ 进入虚拟环境 sudo pip install pymongo 或源码安装 python setup.py ~~~ * 引入包pymongo ~~~ import pymongo ~~~ * 连接,创建客户端 ~~~ client=pymongo.MongoClient("localhost", 27017) ~~~ * 获得数据库test1 ~~~ db=client.test1 ~~~ * 获得集合stu ~~~ stu = db.stu ~~~ * 添加文档 ~~~ s1={name:'gj',age:18} s1_id = stu.insert_one(s1).inserted_id ~~~ * 查找一个文档 ~~~ s2=stu.find_one() ~~~ * 查找多个文档1 ~~~ for cur in stu.find(): print cur ~~~ * 查找多个文档2 ~~~ cur=stu.find() cur.next() cur.next() cur.next() ~~~ * 获取文档个数 ~~~ print stu.count() ~~~