Reputation: 32391
I have documents in my db that may be missing a particular Boolean field. I need to return the set of documents where either this field is missing or exists, but is false. How would I accomplish this?
Upvotes: 2
Views: 91
Reputation: 1655
You can use a JavaScript function as a filter in which the current document is this
. It's not as efficient as using a combination of $exists
$or
$eq
but it allows you to use the familiar JS idiom for testing the falsy-ness (and/or non-existence) of a property:
db.myCollection.find( function() { return !this.field; } );
More at: http://docs.mongodb.org/manual/reference/operator/query/where/
Upvotes: 0
Reputation: 3829
it's possible using $exists:
db.document.find( { bln : { $exists : true } } );
This query will select all documents in the document collection where the bln field exists
db.document.find( { bln : { $exists : false } } );
This query will select all documents in the document collection where the bln field not exists
Upvotes: 1
Reputation: 141
I looks like you want a combination of
http://docs.mongodb.org/manual/reference/operator/not/
http://docs.mongodb.org/manual/reference/operator/exists/
http://docs.mongodb.org/manual/reference/operator/or/
Upvotes: 2