【发布时间】:2018-12-31 10:57:36
【问题描述】:
在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 "<stdin>", line 1, in <module>
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 "<stdin>", line 1, in <module>
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.
感谢任何帮助!
【问题讨论】:
标签: python mongodb python-2.7 pymongo