pan6831
1
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"}]
Rubble
2
What code are you using to get the current result?
pan6831
3
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).
system
Closed
5
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.