++ed by:
MARKSTOS BINJOY KEEDI ADAMJS HRUPP

15 PAUSE users
24 non-PAUSE users.

Sebastian Riedel

NAME

Mango::Cursor - MongoDB cursor

SYNOPSIS

  use Mango::Cursor;

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

DESCRIPTION

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

ATTRIBUTES

Mango::Cursor implements the following attributes.

batch_size

  my $size = $cursor->batch_size;
  $cursor  = $cursor->batch_size(10);

Number of documents to fetch in one batch, defaults to 0.

collection

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

Mango::Collection object this cursor belongs to.

comment

  my $comment = $cursor->comment;
  $cursor     = $cursor->comment('Fun query!');

A comment to identify query.

fields

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

Select fields from documents.

hint

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

Force a specific index to be used.

id

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

Cursor id.

limit

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

Limit the number of documents, defaults to 0.

max_scan

  my $max = $cursor->max_scan;
  $cursor = $cursor->max_scan(500);

Limit the number of documents to scan.

query

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

Original query.

skip

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

Number of documents to skip, defaults to 0.

snapshot

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

Use snapshot mode.

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.

tailable

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

Tailable cursor.

timeout

  my $timeout = $cursor->timeout;
  $cursor     = $cursor->timeout(500);

Timeout for query in milliseconds.

METHODS

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

add_batch

  $cursor = $cursor->add_batch($docs);

Add batch of documents to cursor.

all

  my $docs = $cursor->all;

Fetch all documents at once. 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;

build_query

  my $query = $cursor->build_query;
  my $query = $cursor->build_query($explain);

Generate final query with cursor attributes.

clone

  my $clone = $cursor->clone;

Clone cursor.

count

  my $count = $cursor->count;

Count number of documents this cursor can return. You can also append a callback to perform operation non-blocking.

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

distinct

  my $values = $cursor->distinct('foo');

Get all distinct values for key. You can also append a callback to perform operation non-blocking.

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

explain

  my $doc = $cursor->explain;

Provide information on the query plan. You can also append a callback to perform operation non-blocking.

  $cursor->explain(sub {
    my ($cursor, $err, $doc) = @_;
    ...
  });
  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 and kill it on the server. You can also append a callback to perform operation non-blocking.

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

SEE ALSO

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