I've made a simplified collection to show my problem:
db.testcol.insert({ a: 1, msgs: [ { listname: "list1", someinfo: "info"}, { listname: "list2", someinfo: "info"}]});
db.testcol.insert({ a: 1, msgs: [ { listname: "list2", someinfo: "info"}]});
db.testcol.insert({ a: 1, msgs: [ { listname: "list3", someinfo: "info"}]});
db.testcol.insert({ a: 1, msgs: [ { listname: "list4", someinfo: "info"}]});
db.testcol.insert({ a: 1, msgs: [ ]});
db.testcol.insert({ a: 2 });
I need to get all documents from this collection which DOES NOT CONTAIN object with field listname: "list1" in array msgs, in other words I need all docs except first. I have problem with this query, I think I should use $nin operator but I can't find any example how to use it with objects. I've tried queries like this:
db.testcol.find({ "msgs.listName": { "$nin":[ "list1" ] } }).pretty()
db.testcol.find({ "msgs": { "$nin":[ { listName: "list1" } ] } }).pretty()
but all of them doen't work as i need I still can't get the right result. Thanks in advance.