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
php mongodb codeigniter


source to share


No one has answered this question yet

Check out similar questions:

4270
Link. What does this symbol mean in PHP?
2776
How can I prevent SQL injection in PHP?
2664
How can I check if a string contains a specific word?
2024
How do you parse and process HTML / XML in PHP?
1906
How does PHP foreach work?
1624
How do I get PHP errors?
1475
Converting HTML + CSS to PDF with PHP?
1299
How can I query MongoDB with "how"?
1065
Link. What does this error mean in PHP?
33
How to convert string to ObjectId in nativejs mongodb native driver?



All Articles
Loading...
X
Show
Funny
Dev
Pics