作者:嗳__霞骸 | 来源:互联网 | 2022-12-09 18:45
在pymongo
这里遇到了一个真正的障碍性错误,这使我无法继续进行项目。我已经搜索过此案例,但其他类似的帖子及其答案对我却不起作用。
首先,我正在运行:
mongod v3.6.5-2-g9b2264cf14
MongoDB shell version v3.6.5-2-g9b2264cf14
这是我的最小工作/错误产生示例:
myname@myhost ~ $ /usr/bin/python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> db = pymongo.MongoClient("localhost:27017")
>>> db.testcollection.insert({"foo": "bar"})
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/dist-packages/pymongo/collection.py", line 2344, in __call__
self.__name)
TypeError: 'Collection' object is not callable. If you meant to call the 'insert' method on a 'Database' object it is failing because no such method exists.
>>>
建议使用其他StackOverflow主题insert_one()
代替。但是,这为我产生了相同的结果:
myname@myhost ~ $ /usr/bin/python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> db = pymongo.MongoClient("localhost:27017")
>>> db.testcollection.insert_one({"foo": "bar"})
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/dist-packages/pymongo/collection.py", line 2344, in __call__
self.__name)
TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Database' object it is failing because no such method exists.
任何帮助表示赞赏!
1> 小智..:
您尚未选择数据库。“ db”对象是MongoClient对象。您需要获取一个数据库对象。
尝试这个:
db[][].insert();