NAME

Mango::Cursor - MongoDB cursor

SYNOPSIS

use Mango::Cursor;

my $cursor = Mango::Cursor->new(collection => $collection);

DESCRIPTION

Mango::Cursor is a container for MongoDB cursors used by Mango::Collection.

ATTRIBUTES

Mango::Cursor implements the following attributes.

collection

my $collection = $cursor->collection;
$cursor        = $cursor->collection(Mango::Collection->new);

Mango::Collection object this cursor belongs to.

id

my $id  = $cursor->id;
$cursor = $cursor->id(123456);

Cursor id.

limit

my $limit = $cursor->limit;
$cursor   = $cursor->limit(1);

Limit, defaults to 10.

fields

my $fields = $cursor->fields;
$cursor    = $cursor->fields({foo => 1});

Fields.

query

my $query = $cursor->query;
$cursor   = $cursor->query({foo => 'bar'});

Query.

skip

my $skip = $cursor->skip;
$cursor  = $cursor->skip(5);

Documents to skip, defaults to 0.

sort

my $sort = $cursor->sort;
$cursor  = $cursor->sort({foo => 1});

Sort.

METHODS

Mango::Cursor inherits all methods from Mojo::Base and implements the following new ones.

all

my $docs = $cursor->all;

Fetch all documents. You can also append a callback to perform operation non-blocking.

$cursor->all(sub {
  my ($cursor, $err, $docs) = @_;
  ...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

next

my $doc  = $cursor->next;

Fetch next document. You can also append a callback to perform operation non-blocking.

$cursor->next(sub {
  my ($cursor, $err, $doc) = @_;
  ...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

rewind

$cursor->rewind;

Rewind cursor. You can also append a callback to perform operation non-blocking.

$cursor->rewind(sub {
  my $cursor = shift;
  ...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

SEE ALSO

Mango, Mojolicious::Guides, http://mojolicio.us.