0

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.11 to a 3.2.5 MongoDB environment, which may be causing the problem, but, if so, I haven't been able to ascertain how yet.
  • The syntax for $pull has changed in 3.2.5?
  • There are permission issues on the collection which are preventing modification?
  • I'm running pymongo 2.6.2 in virtualenv - perhaps it has some incompatibilities with MongoDB 3.2.5?
user1063287
  • 10,265
  • 25
  • 122
  • 218

1 Answers1

0

Solution

Upgrading to pymongo 3.2.2 causes error:

ServerSelectionTimeoutError: No servers found yet

https://stackoverflow.com/a/31194981/1063287

However, I upgraded to pymongo 2.8, restarted apache and the problem seems to be resolved.

Community
  • 1
  • 1
user1063287
  • 10,265
  • 25
  • 122
  • 218