There is struct of my MongoDB documents:
{
_id : "12345",
name : "foo",
object : {
array_of_objects : [{
id : 507,
name : "some name",
dt : "2012-06-27 16:35:50"
},{
id : 506
name : "some other name",
dt : "2012-06-21 16:09:05"
},
…
]
}
}
I need to get an object from array_of_objects with a certain id of the document with the specified name. I use php and tried to execute the next code:
$collection->find(array('name' => 'foo', 'object.array_of_objects.id' => 507));
It returns all elements of array_of_objects instead of element with id 507. After that I try to make query with $elemMatch:
$collection->find(array('name' => 'foo', 'object.array_of_objects' => array('$elemMatch' => array('id' => 507))));
But it had return the same. :( My MongoDB version 2.0.6. Please help.