Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo findAndUpdate for updating multiple documents

Tags:

mongodb

I am attempting to use mongo findAndUpdate to update multiple documents and keep receiving syntax error:

db.forecasts.findAndModify({
   query: {forDate: ISODate("2016-02-25T05:00:00.000+0000")},
   update: {
      { $set: {forDate: ISODate("2016-02-23T05:00:00.000+0000")}}, 
      {multi: true}
     }
   })

Alternately I also tried:

db.forecasts.update({
   {'forDate': ISODate("2016-02-25T05:00:00.000+0000")},
   {'forDate': ISODate("2016-02-23T05:00:00.000+0000")}, 
   {multi: true}  
   })

The error I receive is : Error at line 2 position 3: <missing ')'

like image 623
runtimeZero Avatar asked Mar 14 '23 04:03

runtimeZero


1 Answers

findAndModify() doesn't allow {multi: true}. You can only update one document and it returns the original doc (default) or uou can ask for thr updated doc.

like image 60
sqa9999 Avatar answered Mar 23 '23 23:03

sqa9999



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!