Mango::Cursor(3pm)

πŸ“¦
version 1.30 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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:


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. πŸ’…βœ¨