Mango:...:Query(3pm)
β¨ NAME β¨
Mango::Cursor::Query β a MongoDB query cursor, bestie π
It's from the User Contributed Perl Documentation (that's the 3pm manual section, iykyk), and this is literally its whole page, rewritten with love π«Ά
πΈ SYNOPSIS πΈ
use Mango::Cursor::Query;
my $cursor = Mango::Cursor::Query->new(collection => $collection);
my $docs = $cursor->all;
okay so that's the whole vibe β make a cursor, grab all the docs. slay β¨
π¦ DESCRIPTION π¦
Mango::Cursor::Query is a container for MongoDB query cursors used by Mango::Collection. That's it, that's the job. It holds your cursor, it lets you poke at it, and Mango::Collection is the one who actually uses it. lowkey simple, highkey essential π
π ATTRIBUTES π
Mango::Cursor::Query inherits all attributes from Mango::Cursor and implements the following new ones. not some of them, bestie β all of them π
π« await_data
my $await = $cursor->await_data;
$cursor = $cursor->await_data(1);
Await data. β³ (yes that's the whole description, no I will not elaborate, the original didn't either π)
π¬ comment
my $comment = $cursor->comment;
$cursor = $cursor->comment('Fun query!');
A comment to identify the query. label your queries like you label your playlists, fr fr π§
π fields
my $fields = $cursor->fields;
$cursor = $cursor->fields({foo => 1});
Select fields from documents. cherry-pick only the keys you want, no cap π
π hint
my $hint = $cursor->hint;
$cursor = $cursor->hint({foo => 1});
Force a specific index to be used. it's giving "use THIS one, I said what I said" π
π max_scan
my $max = $cursor->max_scan;
$cursor = $cursor->max_scan(500);
Limit the number of documents to scan. β don't go overboard
β° max_time_ms
my $max = $cursor->max_time_ms;
$cursor = $cursor->max_time_ms(500);
Timeout for the query, in milliseconds. the query has a curfew and it's 500ms, periodt β
π query
my $query = $cursor->query;
$cursor = $cursor->query({foo => 'bar'});
The original query. the receipts, the source material, the origin story π
π³οΈ read_preference
my $pref = $cursor->read_preference;
$cursor = $cursor->read_preference({mode => 'SECONDARY'});
Read preference. who gets to serve the reads π
βοΈ skip
my $skip = $cursor->skip;
$cursor = $cursor->skip(5);
Number of documents to skip β defaults to 0. no skipping by default, we're not toxic like that π§
πΈ snapshot
my $snapshot = $cursor->snapshot;
$cursor = $cursor->snapshot(1);
Use snapshot mode. π· freeze the moment
π sort
my $sort = $cursor->sort;
$cursor = $cursor->sort({foo => 1});
$cursor = $cursor->sort(bson_doc(foo => 1, bar => -1));
Sort documents. β οΈ the order of keys matters β do NOT come for me about it, it's just true, the ordering is part of the sort and that's that π
π tailable
my $tailable = $cursor->tailable;
$cursor = $cursor->tailable(1);
Tailable cursor. it keeps the tail wagging π
π METHODS π
Mango::Cursor::Query inherits all methods from Mango::Cursor and implements the following new ones. yes, all of them again. iconic behavior β¨
π οΈ build_query
my $query = $cursor->build_query;
my $query = $cursor->build_query($explain);
Generate the final query with the cursor attributes. this is where all your little settings finally become One Real Query π§
π― clone
my $clone = $cursor->clone;
Clone the cursor. everybody needs a twin π
π’ count
my $count = $cursor->count;
Count the number of documents this cursor can return. You can also append a callback to perform the operation non-blocking. look at her go, multitasking β¨
$cursor->count(sub {
my ($cursor, $err, $count) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
note the Mojo::IOLoop->start unless Mojo::IOLoop->is_running; β you need it or nothing happens and you'll be sitting there like ποΈπποΈ
π¨ distinct
my $values = $cursor->distinct('foo');
Get all the distinct values for a key. You can also append a callback to perform the operation non-blocking.
$cursor->distinct(foo => sub {
my ($cursor, $err, $values) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
dedupe your life π
π¬ explain
my $doc = $cursor->explain;
Provide information on the query plan. You can also append a callback to perform the operation non-blocking.
$cursor->explain(sub {
my ($cursor, $err, $doc) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
it's giving "explain yourself" and honestly? we love the transparency π«Ά
π SEE ALSO π
MangoMojolicious::Guides- <http://mojolicio.us>
perl v5.30.3 Β· 2020-06-05 Β· Mango:...:Query(3pm)
and that's the whole page bestie, mwah π go forth and query responsibly π₯π
π¦ where this page comes from
- debian bookworm: libmango-perl 1.30-2 Β· Artistic-2.0
- debian trixie: libmango-perl 1.30-2 Β· Artistic-2.0
- ubuntu jammy: libmango-perl 1.30-2 Β· Artistic-2.0
- ubuntu noble: libmango-perl 1.30-2 Β· Artistic-2.0
- ubuntu resolute: libmango-perl 1.30-2 Β· Artistic-2.0
- ubuntu stonking: libmango-perl 1.30-2 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms