zjor
zjor

Reputation: 1043

$push modifies only first document

I have a query:

db.locations.find({
    "source_id": {
        "$in": [ "1", "3", "4" ]
    }
})

Which returns 3 documents.

I'd like to modify these documents with the following command:

db.locations.update(
    {
        "source_id": {
           "$in": ["1", "3", "4"]}
    }, 
    { "$push": {"services": "IN_EUR"} }
)

But I get only first document updated. Why is that? Documentation on $push doesn't say that <query> should return single document.

Can anyone explain?

Upvotes: 0

Views: 67

Answers (1)

Neil Lunn
Neil Lunn

Reputation: 151132

If your intention is to update multiple documents then add the multi parameter:

db.locations.update(
    {
        "source_id": {
           "$in": ["1", "3", "4"]}
    }, 
    { "$push": {"services": "IN_EUR"} },
    { "multi": true }
)

Upvotes: 3

Related Questions