Shamoon
Shamoon

Reputation: 43617

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.

Upvotes: 7

Views: 1578

Answers (1)

Shamoon
Shamoon

Reputation: 43617

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}"

Upvotes: 14

Related Questions