Now that I'm looking at the problem again, I don't see that usage of find in the MongoDB::Collection docs. Are you sure that you don't want to use find with fields (and then either a slice or limit of the resultant cursor, possibly with a sort_by as well) or find_one instead?
What I have put together here is untested and should be considered pseudo code but it seems to me that one of the following would do the trick.
my $some_users = $collection->find->fields( { crt_by => 1, name => 1, + contacts => { '$slice' => 1 } } ); #my $some_users = $collection->find->limit( 1 )->fields( { crt_by => 1 +, name => 1, contacts => 1 } ); #my $some_users = $collection->find_one( {}, { crt_by => 1, name => 1 +, contacts => 1 } );
In reply to Re^3: Need help with $slice MongoDB
by Mr. Muskrat
in thread Need help with $slice MongoDB
by vinaybond
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |