Bin Chen
Bin Chen

Reputation: 63349

mongodb: how to write below query string

I want to select all the records that meet below criteria:

if "used1" not in record or record["used1"] != True

How to write this? Thanks.

Upvotes: 0

Views: 198

Answers (1)

mu is too short
mu is too short

Reputation: 434745

You'd use $exists for the first:

db.collection.find({ used1: { $exists: false } })

and $ne for the second:

db.collection.find({ used1: { $ne: true } })

To combine them, use $or:

db.collection.find({
    $or: [
        { used1: { $exists: false } },
        { used1: { $ne:     true  } }
    ]
 })

Upvotes: 3

Related Questions