3

I moved from mongo to mongodb extension when I upgraded to PHP7. The only thing I cannot figure out is to update a doc by id. Mongo used to have the MongoId Class to parse the id from string but I can't find any equivalent for Mongodb.

This is where I'm at and which doesn't work

$collection->updateOne(['_id' => '567eba6ea0b67b21dc004687'], ['$set' => ['some_property' => 'some_value']]);   
4

1 回答 1

14

_id应该是 BSON 的一个实例:

$collection->updateOne(['_id' => new \MongoDB\BSON\ObjectID('567eba6ea0b67b21dc004687')], ['$set' => ['some_property' => 'some_value']]);   
于 2016-01-07T13:03:12.287 回答