Mohamed A.B
Mohamed A.B

Reputation: 93

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..

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 enter image description here

Upvotes: 0

Views: 653

Answers (1)

lghh
lghh

Reputation: 303

I think one possible solution could be to replace ISODate with ObjectId in your query string.

Moreover, delete_one deletes the first object which matches with your query. So it is possible that there exist multiple objects which match your query?

Upvotes: 1

Related Questions