Trying to query nested documents(message collection) with embedded fields from an other collection(user)
here it is an example of the document i want to query:
array (
'_id' => new MongoId("52454de22660b239178b4567"),
'from_uid' => array (
'uid' => '5231817277758e660c7202d7',
'uname' => 'franc',),
'to_uid' => '5231817277758e660c7202d7',
'object' => 'improving',
'content' => 'mongo mega newbie bro',
'datetime' => '2013-09-27 11:20:34',
)
I would (with just 1 query if it's possible) get and display the fallowing fields:
- uname (value of the 'from_uid' sub-array)
- object
- content
- datetime
I have tryed in many ways without success, and starting to going crazy.. my last try was:
$m = new MongoClient();
$db = $m->mydb;
try{
$array_qry = iterator_to_array($db->message->find(array("to_uid" => $this->uid_logged), array( "_id" => 0, "from_uid" => array('from_uid.uid' => 0, 'from_uid.uname' => 1), "to_uid" => 0, "object" => 1, "content" => 1, "datetime" => 1)));
}catch(MongoCursorException $e) {
echo "error message: ".$e->getMessage()."<br/>";
echo "error code: ".$e->getCode()."<br/>";
}
foreach ($array_qry as $k => $v) {
print_r($v);
}
the first array of the query define to select just the messages where the to_uid field is equal to the user_id of the user logged(sound obvious right?). Then there is the array and the sub-array(where probably is the error) for pick the fields.
I get this output, the warning is surely just a consequence of the wrong query that don't return any result:
error message: localhost:27017: Unsupported projection option: from_uid.uid
error code: 13097
Warning: Invalid argument supplied for foreach() in /var/www/nosql_portal/inc/classi/msg.class.php on line 128
Any help is appreciated