thephpleague / monga

Simple and swift MongoDB abstraction.
MIT License
331 stars 30 forks source link

Not issue : multiple update #20

Closed rhnkyr closed 9 years ago

rhnkyr commented 9 years ago

How to update multiple docs at the same time.

For instance my doc :

{
    "_id" : ObjectId("54c05ef742f5420ca4ef1328"),
    "title" : "Lorem ipsum",
    "creator" : {
        "mid" : ObjectId("54a6ebd4f66b87b44c0041a7"),
        "name" : "John Do",
        "picture" : "https://limcdn.s3-eu-west-1.amazonaws.com/asasasasasasa.jpg",
        "is_verified" : 1
    }
}

i find docs by creator.mid and i want to set creator name every docs in collection.

bcrowe commented 9 years ago

You should be able to do something like this:

$collection = $database->collection('articles');
$newName = 'Bryan';
$collection->update(function ($query) use ($newName) {
     $query->set('creator.name', $newName)
        ->where('creator.mid', ...);
});
rhnkyr commented 9 years ago

@bcrowe thank you m8.