I have two items in MongoDB:
{\'title\':\'active item\',
\'tags\':[
{\'tag\':\'active\'},
{\'tag\':\'anothertag\'}
]}
{\'title\':\'completed
You can do it with $ne operator.
db.items.find({"tags.tag" : {$ne : "completed"}})
The target of the $not operator needs to be an operator-expression, not a field/value object.
So parvin's answer is the easiest way to do this, but just for learning purposes, you can do this with $not
by using $not
supported expressions like:
db.items.find({tags: {$not: {$elemMatch: {tag: 'completed'}}}})
db.items.find({'tags.tag': {$not: /completed/}})