1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ......

TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ......

时间:2021-06-27 03:45:14

相关推荐

TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ......

运行 Scrapy 项目时,出现以下报错:

Traceback (most recent call last):File "G:\Anaconda\Anaconda\lib\site-packages\twisted\internet\defer.py", line 857, in _runCallbackscurrent.result = callback( # type: ignore[misc]File "G:\Anaconda\Anaconda\lib\site-packages\scrapy\utils\defer.py", line 162, in freturn deferred_from_coro(coro_f(*coro_args, **coro_kwargs))File "G:\Python\images360\images360\pipelines.py", line 33, in process_itemself.db[name].insert(dict(item))File "G:\Anaconda\Anaconda\lib\site-packages\pymongo\collection.py", line 2779, in __call__raise TypeError(TypeError: 'Collection' object is not callable. If you meant to call the 'insert' method on a 'Collection' object it is failing because no such method exists.

报错为:

TypeError: 'Collection' object is not callable. If you meant to call the 'insert' method on a 'Collection' object it is failing because no such method exists.

翻译:

类型错误:“Collection”对象不可调用。如果您打算对“Collection”对象调用“insert”方法,则会失败,因为不存在此类方法。

错误原因:

PyMongo 4.0.* 中 Collection.insert 方法被移除,使用Collection.insert_one 或者Collection.insert_many 替代:

collection.insert_one({'my': 'document'})collection.insert_many([{'doc': 2}, {'doc': 3}])

相关更改链接:PyMongo 4 collection-insert-is-removed

官方文档:PyMongo 4 Migration Guide — PyMongo 4.0.2 documentation可查看 PyMongo 相关信息

CMD 查看 PyMongo 版本:

pip list -v

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。