【发布时间】:2015-05-12 22:52:50
【问题描述】:
跟随 PyMongo tutorial 并在集合上调用 insert_one 方法时遇到错误。
In [1]: import pymongo
In [2]: from pymongo import MongoClient
In [3]: client = MongoClient()
In [4]: db = client.new_db
In [5]: db
Out[5]: Database(MongoClient('localhost', 27017), u'new_db')
In [6]: posts = db.posts
In [7]: posts.insert_one({'a':1})
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-2271c01f9a85> in <module>()
----> 1 posts.insert_one({'a':1})
C:\Anaconda\lib\site-packages\pymongo-2.8-py2.7-win32.egg\pymongo\collection.py in __call__(self, *a
rgs, **kwargs)
1771 "call the '%s' method on a 'Collection' object it is "
1772 "failing because no such method exists." %
-> 1773 self.__name.split(".")[-1])
TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.
网上有一些帖子讨论了这个错误,但似乎都是当用户调用一个已弃用的名称时。
关于我在这里做错了什么的任何指导?
【问题讨论】:
-
我想补充一点,这是这里所谓的“清晰”示例的示例。这些监控会很好地效仿。
-
这也发生在我身上。感谢您发布 =)。