check for multiple attributes existence

Naughty.Coder

I know how o check if a document has an attribute:
db.things.find({otherInfo:{'$exists':true}});

But what if I want to check if more than one attribute exist ?

Christian P

The $exists method is not special. It just checks the documents that have the field you specified. You can use it like you would use any other operator in MongoDB.

If you need to check multiple attributes, you just need to add them to the query:

db.things.find({ 
    otherInfo: { $exists: true },
    foo: { $exists: true },
    bar: { $exists: true },
    a : 123,
    b : 234
    /* ... */
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive