How to convert string to ObjectId in native php mongodb driver?
I am using mongodb driver in php environment (frameworkign framework) and I need to convert id string to ObjectId in order to use it in my update request, how can I do that? I've tried the following code but it doesn't work.
$collection->update(array('_id'=> $NewDeviceArray["myid"], $newdata);
I also tried a suggestion on google to convert string to objectid.but but that also failed.
$convertedid= new MongoId($NewDeviceArray["myid"]);
$collection->update(array('_id'=> $convertedid, $newdata);
Any hints would be much appreciated.
Update
after fixing the syntax error, $ collection-> update (array ('_ id' => $ conversionid), $ newdata);
Now it works !!!
+3
source to share
No one has answered this question yet
Check out similar questions: