简体   繁体   中英

Mongoose update only updates first document

Okay.. this is odd and annoying, so any help would be GREATLY appreciated. Here's my code:

        Target.update {location_city: "New York"}, {location_country: "FUDGE!"}, {safe: true}, (err, res) ->
          console.log "Updating with New York"
          console.log res
          console.log "Err #{err}"

No error, NADA. BUT only the FIRST document gets updated for some reason. When I run a find on the SAME query, I get multiple results.

Any help would be AWESOMELY appreciated.

multi has to be true .

So the correct query would be

    Target.update {location_city: "New York"}, {location_country: "FUDGE!"}, {multi: true}, (err, res) ->
      console.log "Updating with New York"
      console.log res
      console.log "Err #{err}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM