I have two items in MongoDB:
{'title':'active item',
'tags':[
{'tag':'active'},
{'tag':'anothertag'}
]}
{'title':'completed item',
'tags':[
{'tag':'completed'}
]}
It works to find items which are tagged as completed:
db.items.find({'tags.tag':'completed'})
RESULT: [<completed item>]
Now, I want to select all items which are not tagged as completed, so I tried:
db.items.find({$not:{'tags.tag':'completed'}})
DESIRED RESULT: [<active item>]
ACTUAL RESULT: []
But somehow this doesn't return any results. Clearly I misunderstand $not in Mongo, but why? How do I query to find the records that do not contain a given value in their tags?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…