I have a script that store Data in a MongoDB, and I'd like to delete document with another script. Each document stored in my DB comes in this format :
{"k1526346000_500":
{"r45037": {"C": "1", "V": "1000", "L": "1181", "D": "75"},
{"r21542": {"C": "2", "V": "94527", "L": "105", "D": "94"},
etc...
}
What I'd like to do is to delete a document by passing the key (k1526346000_500 in this case) When I try to do :
db.collection.delete_one({_id:key})
Where key corresponds to k1526346000_500, I have an error :
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "fetch.py", line 38, in run
read(self.mongo).test(key)
File "/var/python/lib/script.py", line 121, in test
db.collection.delete_one({_id:key})
NameError: global name '_id' is not defined
BUT, the document is correctly deleted. It's a problem for me because the error exits the script, and I have to make it run in an loop.
Do you know how can I make it work ?
Thanks ;)
EDIT : When I dump that document, I have this result :
{ "_id" : ObjectId("5afda3efb2031025afe0d32e"), "k1526346000_500" : { "r4" : { "C" : "1", "V" : "447616", "L" : "1", "D" : "4" }
So this is definitely not "_id" to use here, but I don't know how to catch this field :(