Mango::Cursor(3pm)
π Mango::Cursor β the manual, but make it cute π
okay bestie, welcome to Mango::Cursor, a page from the User Contributed Perl Documentation era, and honestly? it's giving β¨container energyβ¨. Let's get into it.
β¨ NAME β¨
Mango::Cursor β a MongoDB cursor, fr fr. That's the whole vibe. π¦
πΈ SYNOPSIS πΈ
look at this, it's so clean, so demure:
use Mango::Cursor;
my $cursor = Mango::Cursor->new(collection => $collection);
my $docs = $cursor->all;
that's it. that's the whole thing. iconic. π
π DESCRIPTION π
Mango::Cursor is literally just a container for MongoDB cursors β and the ones using it are Mango::Collection. so like, if a Mango::Collection is the main character, Mango::Cursor is the bestie holding its stuff. no cap. π«Ά
π ATTRIBUTES π
Mango::Cursor implements the following attributes. yes, all of them. we're not skipping any, that's not the vibe.
π batch_size
my $size = $cursor->batch_size;
$cursor = $cursor->batch_size(10);
this is how many documents you grab in one batch. defaults to 0. zero. nothing. nada. π
π§ collection
my $collection = $cursor->collection;
$cursor = $cursor->collection(Mango::Collection->new);
the Mango::Collection object that this cursor belongs to. it's the cursor's home, its safe place, its whole world. π
β id
my $id = $cursor->id;
$cursor = $cursor->id(123456);
the cursor id. that's it. that's the description. sometimes things are simple and that's beautiful. β¨
π limit
my $limit = $cursor->limit;
$cursor = $cursor->limit(10);
caps how many documents you get. defaults to 0, which means no cap, go wild, live your truth. π₯
π METHODS π
Mango::Cursor inherits all methods from Mojo::Base and also implements these brand new ones. glow up behavior only.
π¦ add_batch
$cursor = $cursor->add_batch($docs);
adds a batch of documents to the cursor. yes, a whole batch. we love a bulk moment. π
π all
my $docs = $cursor->all;
fetches all the documents at once. the way that it just... gets everything? obsessed. π
you can also append a callback to do the operation non-blocking, like this:
$cursor->all(sub {
my ($cursor, $err, $docs) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
see that last line? don't forget it, bestie, or nothing's gonna happen. π«Ά
πΈ next
my $doc = $cursor->next;
fetches the next document. one at a time, taking it slow, living in the moment. β¨
you can also append a callback to do the operation non-blocking:
$cursor->next(sub {
my ($cursor, $err, $doc) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
again with the Mojo::IOLoop->start unless Mojo::IOLoop->is_running;. it's the moment before the moment, iykyk. π
π rewind
$cursor->rewind;
rewinds the cursor and kills it on the server. yes, KILLS IT. π dramatic? maybe. accurate? absolutely. do not forget that part.
you can also append a callback to do the operation non-blocking:
$cursor->rewind(sub {
my ($cursor, $err) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
β οΈ bestie, real talk: this one does NOT mess around. rewind = rewind + kill on the server. that's not a vibe check, that's a vibe execution. π«Ά
π num_to_return
my $num = $cursor->num_to_return;
how many results you're gonna return with the next "QUERY" or "GET_MORE" operation β and it figures that out based on "batch_size" and "limit". the math is mathing. π₯
π SEE ALSO π
go look at these, they're the supporting cast and they ate:
MangoMojolicious::Guides- <http://mojolicio.us>
and that's the whole page, bestie. no cap, we kept every single flag, every default, every code block, every warning. periodt. π
this was perl v5.30.3, dated 2020-06-05, and it's Mango::Cursor(3pm) β thank you for coming to my TED talk, mwah. π
β¨
π¦ 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