9
db.movieDetails.updateMany({
    "tomato.consensus": null,
    "imdb.votes":{$lt:10000},
    "year":{$gte:2010,$lte:2013}},
    {
       $unset:{"tomato.consensus":""
    }
})

When I typed the command above in the mongo shell, I received an error that stated that updateMany was not a valid function.

TypeError: Property 'updateMany' of object video.movieDetails is not a function at (shell):1:17

I checked the documentation and updateMany is listed a valid function. I would like to know why I received the error.

Syed Faizan
  • 901
  • 3
  • 14
  • 28

2 Answers2

7

this worked for me

 db.collection.update({},{$set:{,is_expired:false}},{multi:true})
Apoorv
  • 1,338
  • 1
  • 17
  • 18
5

The updateMany command has not been deprecated. You'll find the documentation for the command here: db.collection.updateMany.

You were unable to use the command because it was introduced in the 3.2 version of MongoDB. You need to install the 3.2 version to use the updateMany command.

gnerkus
  • 11,357
  • 6
  • 47
  • 71
  • Thanks, i was using 3.0.2 :( – Syed Faizan Jan 19 '16 at 05:33
  • 5
    From my reading of the docs `update` using the `multi` flag should do the same thing as `updateMany`. Is this true? – matth Jun 03 '16 at 19:52
  • 2
    @matth if you are using monogdb 2.2 then db.test.update({foo: "bar"}, {$set: {test: "success!"}}, {multi: true}) – Nitin Oct 30 '17 at 05:07
  • @gnerkus my MongoDB version: 3.2.15 it works in shell but when i try to call from node then it shows updateMany is not a function as it works by giving multi true but can i do by the updateMany? – Nitin Oct 30 '17 at 05:09