RussellHarrower
RussellHarrower

Reputation: 6810

mongoDB PHP query where is NOT

ok I need a quick way to do the following with mongoDB

I was looking to do a query that would search for anything that did NOT have the word Apple in the fruit or veg column in the collection

here etc

{
 "fruit":"apple"
},{
 "fruit":"orange"
},{
 "fruit":"banana"
}

Upvotes: 1

Views: 1953

Answers (1)

Stennie
Stennie

Reputation: 65323

The operator you probably want to use is $nin ("not in"):

db.market.find({
    'fruit': {$nin:['apple']},
    'veg':   {$nin:['apple']}
})

You could also use $not to negate a standard where condition.

Upvotes: 2

Related Questions