简体   繁体   English

无法使用pymongo删除mongodb文档

[英]Can't delete mongodb document using pymongo

I'm trying to delete one specific document using (_id) with pymongo and i can't do it, some idea.. 我正在尝试使用(_id)和pymongo删除一个特定文档,但我做不到,有些想法。

thks. THKS。

I have this code: 我有以下代码:

s = "ISODate('{0}')".format(nom_fitxer_clean)
#i generate the next string.. (ISODate('2018-11-07 00:00:00'))

myquery = { "_id": s }
#query string ({'_id': "ISODate('2018-10-07 00:00:00')"})
mycol.delete_one(myquery)

I do not get any errors or delete the document. 我没有任何错误或删除文档。

UPDATE: Document 更新:文档 在此处输入图片说明

I think one possible solution could be to replace ISODate with ObjectId in your query string. 我认为一种可能的解决方案是在查询字符串中用ObjectId替换ISODate。

Moreover, delete_one deletes the first object which matches with your query. 此外, delete_one删除与您的查询匹配的第一个对象。 So it is possible that there exist multiple objects which match your query? 因此,可能存在多个与您的查询匹配的对象?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM