Python与mongo交互

时间:2020-02-26 14:20:34   收藏:0   阅读:72
# 导入模块
import pymongo
# 连接MongoDB数据库
conn = pymongo.MongoClient(localhost, 27017)
# 建库
db = conn.goods
# 建集合
table = db.snacks
# 数据操作: 插入数据
table.insert(dict)
table.insert_one(dict)
table.insert_many([dict1, dict2, dict3])
# 数据操作: 查询数据
table.find_one({dict})  # 返回一个字典形式数据
table.find()  # 返回一个mongo对象, 需要使用for循环遍历取值
table.find({dict})  # 同上

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!