Aysennoussi
Aysennoussi

Reputation: 3860

Update all field values that match a criteria

I'm trying to change the value of author where the value is lower than 0 I use this but no result :

db.posts.update({author:{$lt:0}},{$set:{author:582127753}})

any Ideas ?

Upvotes: 3

Views: 1110

Answers (1)

Josh
Josh

Reputation: 5721

From the Mongo docs-

By default, the update() method updates a single document that matches its selection criteria. Call the method with the multi option set to true to update multiple documents.

So you should run your query like this:

db.posts.update(
  {author:{$lt:0}},
  {$set:{author:582127753}},
  { multi: true }
)

Upvotes: 8

Related Questions