How to Get response in the below manner using Mongodb and PHP

I’m fetching data using php and mongodb. But its returning data in the below format.

   [ {"5a67138a75ad6124138dcef2":{"_id":{"$id":"5a67138a75ad6124138dcef2"},"buname":null,"imgurl":null,"desg":null,"piurl":"byebye","uname":"aaa"}]

I want op in the below format, what I should i do.

       array(1)[array(0)=>{"_id":"5a67138a75ad6124138dcef2","buname":null,"imgurl":null,"desg":null,"piurl":"byebye","uname":"aaa"}]

What code are you using to get the current result?

Below is my code:

 $con = new DbConnect();
 $db  = $con->connect();
 $collection = new MongoCollection($db,'contact');
 $document = $collection->find(array("login_name"=>$luname),array("_id"=>0,"imgurl"=>1,"piurl"=>1,"buname"=>1,"desg"=>1,"uname"=>1));
 $res = iterator_to_array($document);

There’s a suggestion that using iterator_to_array() isn’t a good way, that you should use a cursor instead - http://www.php.net/manual/en/class.mongocursor.php

(I have no mongo experience, I should say, but maybe it retrieves the data in a format you want).

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.