What is the right command to do so. -Vinay{ "_id" : ObjectId("52dfd2750cf2169251fe8d3c"), "closed_on" : ISODate("2014-01-30T18:30:00Z"), "companies" : [ { "_id" : ObjectId("52dfd2750cf2169251fe8d3f"), "comp_name" : "Test1", }, { "_id" : ObjectId("52dfd7950cf2169251fe8d47"), "comp_name" : "Test2", } ], "contacts" : [ { "_id" : ObjectId("52dfd2750cf2169251fe8d3e"), "fname" : "Solve", "lname" : "Scottt", "email" : "email1@gmail.com", "company" : "Test111", }, { "_id" : ObjectId("52dfd7950cf2169251fe8d46"), "fname" : "signe", "lname" : "towne", "email" : "email2@gmail.com", "company" : "Test222", } ], "crt_by" : "creator@gmail.com", "currency" : "USD", "type" : "None", } I need: crt_by conatacts.fname ( from the first record of the contacts array) conatacts.company ( from the first record of the contacts array) I tried using $slice like this. my $output = $collection->find({} },{ crt_by => 1, 'contacts' => {'$s +lice' => 1} }); and when I am printing the the record it shows me some array for conta +cts. while (my $doc = $output->next) { $output.= "\t- ".$doc->{'crt_by'}." Contact".$doc->{'c +ontacts.fname'}."\n"; } } print "$ouput\n";
In reply to Need help with $slice MongoDB by vinaybond
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |