julio sagasta
julio sagasta

Reputation: 9

How to perform a negative query in Mongodb?

How to perform a query (.find) in MongoDB indicating that I do NOT want a word to appear in one of the document fields.

Thanks

I dont know the excatly command

Upvotes: 0

Views: 379

Answers (1)

NeNaD
NeNaD

Reputation: 20304

You can do it with $not and $regex operators:

db.collection.find({
  "field": {
    "$not": {
      "$regex": "some"
    }
  }
})

Working example

Upvotes: 1

Related Questions