【发布时间】:2018-06-29 22:29:53
【问题描述】:
我希望将数据插入到 mycollection 中,但是当我在 insert_one 之前使用集合变量时,它实际上会插入到名为“collection”的集合中。
client = MongoClient()
db = client['mydb']
collection = db['mycollection']
db.collection.insert_one({"id": "hello"})
【问题讨论】:
-
你没有使用集合变量,你使用的是 db.collection。