Mandel::Collection - A collection of Mandel documents
my $connection = MyModel->connect("mongodb://localhost/my_db"); my $persons = $connection->collection("person"); $persons->count(sub { my($persons, $err, $int) = @_; }); # ...
This class is used to describe a group of mongodb documents.
An object that inherit from Mandel.
An object that inherit from Mandel::Model.
$self = $self->all(sub { my($self, $err, $docs) = @_; }); $docs = $self->all;
Retrieves all documents from the database that match the given "search" query.
$document = $self->create; $document = $self->create(\%args);
Returns a new object of a given type. This object is NOT inserted into the mongodb collection. You need to call "save" in Mandel::Document for that to happen.
%args is used to set the fields in the new document, NOT the attributes.
%args
$self = $self->count(sub { my($self, $err, $int) = @_; }); $int = $self->count;
Used to count how many documents the current "search" query match.
$self = $self->distinct("field_name", sub { my($self, $err, $values) = @_; }); $values = $self->distinct("field_name");
Get all distinct values for key in this collection.
$iterator = $self->iterator;
Returns a Mandel::Iterator object based on the "search" performed.
$self = $self->patch(\%changes, sub { my($self, $err, $doc) = @_ }); $self = $self->patch(\%changes);
This method can be used to add %changes to multiple documents in the collection. Which documents to update will be decided by the %query given to "search".
%changes
%query
%extra arguments default to:
%extra
upsert: false
multi: true
$self = $self->remove(sub { my($self, $err) = @_; }); $self = $self->remove;
Remove the documents that query given to "search".
$self = $self->save(\%document, sub { my($self, $err, $doc) = @_; ); $doc = $self->save(\%document);
Used to save a document. The callback receives a Mandel::Document.
$clone = $self->search(\%query, \%extra);
Return a clone of the given collection, but with different %search and %extra parameters. You can chain these calls to make the query more precise.
%search
%extra will be used to set extra parameters on the Mango::Cursor, where all the keys need to match the "ATTRIBUTES" in Mango::Cursor.
$self = $self->single(sub { my($self, $err, $doc) = @_; }); $doc = $self->single;
Will return the first object found in the callback, matching the given %search query.
Mojolicious, Mango, Mandel
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
To install Mandel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mandel
CPAN shell
perl -MCPAN -e shell install Mandel
For more information on module installation, please visit the detailed CPAN module installation guide.