-1

I took this example:

db.inventory.update( { tags: { $nin: [ "appliances", "school" ] } }, { $set: { sale: false } } )

form the mongodb.org website.

Whenever I try to use $nin multiple times, find_and_modify fails. Whan I want to achieve:

db.inventory.update( { tags: { $nin: [ "appliances", "school" ]}, owners: {$nin : ["a","b"] }, { $set: { sale: false } } )

But it seems like I am not allowed to use $nin mutiple times. I know $push can't be used like that, so I just use $push on multiple fields once. But how can use it for the $nin?

meso_2600
  • 1,940
  • 5
  • 25
  • 50
  • Could you provide actual query and example documents? You can use `$nin` multiple times in the query so my I guess is your problem lies somewhere else. – zero323 Nov 25 '13 at 22:06

1 Answers1

1

You can use $nin multiple times. Here is an example:

db.a.insert({odd : [1, 3, 5, 7, 9], even : [0, 2, 4, 6, 8]})
 db.a.find({
   odd : {$nin : [2, 6]},
   even : {$nin : [3, 7, 9]}
 }); // will return a document

 db.a.find({
   odd : {$nin : [2, 6, 1]},
   even : {$nin : [3, 7, 9]}
 }); // will NOT return a document because first odd has 1

 db.a.find({
   odd : {$nin : [2, 6, 1]},
   even : {$nin : [3, 7, 9]}
 }); // will NOT return a document because second even has 2

If it can find it, correctly then it can modify it as well

db.a.update(
  {odd : {$nin : [2, 6]}, even : {$nin : [3, 7, 9]}},
  {$set : {'correct' : 1}}
)
db.a.find().pretty()

Which suggests just one problem: you have done something wrong.

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753