I am getting a 500 error on a getJSON request which maps to a Python 2.7 function containing a MongoDB update with $pull.
Last error seen with sudo tail -f /var/log/apache2/error.log is:
[wsgi:error] [pid 1721:tid 140612911712000]
[client 127.0.0.1:59078]
KeyError: 'nModified', referer: http://localhost/control_room
The Python logic that deals with this particular key is an update with $pull:
update_with_pull = collection.update({"user_email":user_email,"top_level.year":entry_year,"top_level.month":entry_month}, { "$pull": {dynamic_nested_key: {"timestamp":entry_timestamp}}})
The conditional after this is trying to catch if a document has been modified or not with:
if update_with_pull['nModified'] == 1:
#do stuff
I tested the same operation in the mongo shell and it returned:
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
So it seems to be matching the query but not doing any modifications.
To further troubleshoot, the entry_timestamp value which is used in the $pull section above is consistent in the database and the function (ie they are both strings with the same characters).
Some ideas:
- I've just moved the application from a
2.6.11to a3.2.5MongoDB environment, which may be causing the problem, but, if so, I haven't been able to ascertain how yet. - The syntax for
$pullhas changed in3.2.5? - There are permission issues on the collection which are preventing modification?
- I'm running
pymongo 2.6.2invirtualenv- perhaps it has some incompatibilities with MongoDB3.2.5?