python - MongoDB: How to determine is specific value does not exist -


i can find examples find if specific keys not exist.

i have specific documents in mongodb instance have fields this:

        "actions" : [             {                     "date" : "2015-03-09t15:28:03z",                     "reason" : "",                     "begin_date" : "2015-03-09t15:28:03z",                     "end_date" : "2015-03-09t15:28:03z",                     "action_type" : "block",                     "performed_date" : "2015-03-09t15:28:03z",                     "active" : "on",             },             {                     "date" : "2015-03-09t15:28:03z",                     "reason" : "",                     "begin_date" : "2015-03-09t15:28:03z",                     "end_date" : "2015-03-09t15:28:03z",                     "action_type" : "alert",                     "performed_date" : "2015-03-09t15:28:03z",                     "active" : "on",             },             {                     "date" : "2015-03-09t15:28:03z",                     "reason" : "none",                     "begin_date" : "2015-03-09t15:28:03z",                     "end_date" : "2015-03-09t15:28:03z",                     "action_type" : "history",                     "performed_date" : "2015-03-09t15:28:03z",                     "active" : "on",             }     ], 

now, trying generate query return records "action_type": "history" not exist.

i know $exists operator can tell me if "action_type" key doesn't exist, can't find examples tell me can specify value doesn't exist.

in head want it's (but doesn't work):

db.collection.find({ "actions":{"$elemmatch":{"action_type": "history"}} : { '$exists': false} } ) 

hopefully lot easier making out be.

should work:

db.collection.find({"actions.action_type": {"$ne": "history"}}) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -