【发布时间】:2016-08-13 19:33:05
【问题描述】:
client = MongoClient(conn)
db = client.get_default_database()
json_file = {'test_1':1, 'test_2':2}
db.insert_one(json_file)
生成:
TypeError: 'Collection' object is not callable. If you meant to call the 'insert_many' method on a 'Database' object it is failing because no such method exists.
检查我的 pymongo 版本:
$ pip freeze | grep pymongo
$ pymongo==3.2.2
我认为这意味着insert_one 和insert_many 方法应该可用(发布pymongo 3.0,对吗?)。更令人困惑的是,当我调用 dir(db) 时,我根本看不到对任何 insert 方法的任何引用。
我错过了什么?
【问题讨论】:
-
很难调试 cyrptic 错误消息 "'Collection' 对象不可调用。如果您打算在 '数据库'对象”。欢迎来到
pymongo。下次,不要只看一眼文档(和错误消息)。
标签: json mongodb pymongo pymongo-3.x