This is the object which I inserted to mongodb.
{
'_array': [1,2,3],
'_ass_array': [{'num': 1, 'name': 'One'}],
'_obj': {'key': 'val'}
}
If I query on terminal, I can get the same as I inserted. But while querying via PHP's MongoCollection::findOne()/ MongoCollection::find()
, I am getting following format.
{
'_array': { 0: 1, 1: 2, 2: 3},
'_ass_array': {
0: {'num': 1, 'name': 'One'}
},
'_obj': {'key': 'val'}
}
Is there any way I can get the array as array and object as object? if required, I can update the question with the complete code.
On the same data this works for me. Just wondering if you are doing something different in a serialization since the JSON syntax in the post. As expected $data
is a PHP array.
<?php
$dbhost = 'localhost';
$dbname = 'test';
$m = new Mongo("mongodb://$dbhost");
$db = $m->$dbname;
$col = $db->data;
$data = $col->findOne();
echo json_encode( $data ) . "
";
?>
A little intrigued how you arrived at your result, as various people here have that format in their MongoDB documents.