Here is my sample json.
{ "_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";
What is the right command to do so. -Vinay

In reply to Need help with $slice MongoDB by vinaybond

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.