PyMongo的集合对象不是可调用错误 [英] Collection object is not callable error with PyMongo

查看:90
本文介绍了PyMongo的集合对象不是可调用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照PyMongo 教程进行操作,并且在调用insert_one集合上的方法.

Following along the PyMongo tutorial and am getting an error when calling the insert_one method on a collection.

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.

网上有一些帖子讨论了这个错误,但似乎都是在用户调用不赞成使用的名称时出现的.

There are a few posts online that discuss this error but all seem to be when the user calls a deprecated name.

关于我在这里做错什么的任何指导吗?

Any guidance on what I am doing wrong here?

推荐答案

这是一个明确的问题,但这里的问题似乎是您正在从发行文档,但很可能您实际上最多安装的是"pymongo" 2.8,而不是您引用的链接中提到的"3.0b".

It is a clear question but the problem here seems to be that you are reading from the "beta" release documentation but in all likelihood you actually at most have "pymongo" 2.8 installed rather than the "3.0b" referred to in the link you quote.

2.8版本教程指向

The 2.8 release tutorial points to the .insert() method instead:

posts.insert({'a':1})

因为 .insert_one() 仅可用在3.0b驱动程序中.

Since .insert_one() is only available in the 3.0b driver.

要么强制安装"beta"驱动程序,要么使用稳定的驱动程序和可用方法.

Either force the installation of the "beta" driver or live with a stable driver and the available methods.

这似乎是当前搜索引擎响应"与"beta版本"匹配为当前"的错误.

This seems to be the fault of the current "search engine response" matching the "beta release" as "current".

这篇关于PyMongo的集合对象不是可调用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆