Reputation: 650
Is there a way to make a query that:
In the end we will receive all documents where certain field have matched condition AND all document where such field doesn't exist at all.
Upvotes: 24
Views: 24263
Reputation: 27487
How about something like this:
db.stackoverflow.find({
$or: [
{ howmuch: { $exists:false } },
{ howmuch:5 }
]})
In the stackoverflow collection, this will find all documents that do not have the howmuch
field plus all documents that do have howmuch
set to 5.
Upvotes: 56