Skip to content
Advertisement

Properly parse a Mongo cursor to PHP

When converting a MongoCursor to PHP I use this script. Which was presented here StackOverflowSO

using the upper method, the structure is same but _id is whereas using the lower script which yields the below included result.

Unfortunately, this results in the actual object being embedded into an array with the _id from Mongo. Like this :

JavaScript

Since I am passing this object to another service for processing the _id is not known.

How can I convince the PHP Driver to parse the object properly?

Advertisement

Answer

Basically what I did was this.

JavaScript

But this created the aforementioned object which is not what I needed.

I solved it in this way.

JavaScript

return json_encode($return);

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement