收集'对象不可呼应。如果您打算调用更新'收集'对象失败了,因为不存在这样的方法
我试图使用Pymongo将记录保存到Mongo DB中。如果存在或插入一个记录,我有脚本可以更新集合。该片段在交互式运行时起作用,但是当我尝试从Docker做同样的操作时,脚本会失败,而错误 - 集合的对象是无法callable的。如果您打算在“集合”对象上调用“更新”方法,则由于不存在这种方法而失败。
def store_failed_cbsd(id,data,collection_name,mongo_client):
output_content = {'_id' : id,'data' : [data]}
key = {'_id': id}
mongo_client.get_database()[collection_name].update(key,
output_content, upsert=True)
Pymongo版本-4.1.1 我想念什么?
I am trying to save a record into mongo db using pymongo. I have the script to update the collection if it exists or insert one record. This snippet works when run interactively, but when I try to do the same from docker, the script fails with the error - Collection' object is not callable. If you meant to call the 'update' method on a 'Collection' object it is failing because no such method exists.
def store_failed_cbsd(id,data,collection_name,mongo_client):
output_content = {'_id' : id,'data' : [data]}
key = {'_id': id}
mongo_client.get_database()[collection_name].update(key,
output_content, upsert=True)
PyMongo Version - 4.1.1
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
update()
对pymongo 4进行了弃用。使用update_many()
或update_one()
而不是。https://pymongo.readthedocs.io /en/stable/migrate-to-pymongo4.html#Collection-update-is-bemped
update()
was deprecated for pymongo 4. Useupdate_many()
orupdate_one()
instead.https://pymongo.readthedocs.io/en/stable/migrate-to-pymongo4.html#collection-update-is-removed