Mongol::Entity
package Address { use Moose; extends 'Mongol::Base'; has 'street' => ( is => 'ro', isa => 'Str', required => 1 ); has 'number' => ( is => 'ro', isa => 'Int', required => 1, ); __PACKAGE__->meta()->make_immutable(); } package Person { use Moose; extends 'Mongol::Base'; with 'Mongol::Entity'; has 'first_name' => ( is => 'ro', isa => 'Str', required => 1, ); has 'last_name' => ( is => 'ro', isa => 'Str', required => 1, ); has 'age' => ( is => 'ro', isa => 'Int', required => 1, ); has 'addresses' => ( is => 'ro', isa => 'ArrayRef[Address]', default => sub { [] }, traits => [ qw( Array ) ], handles => { add_address => 'push', } ); __PACKAGE__->meta()->make_immutable(); } ... my $person = Person->new( { id => 6161742, first_name => 'John', last_name => 'Doe', age => 30, } ); my $home = Address->new( { street => 'Main St.', number => 123 } ); # --- Saving $person->add_address( $home ); $person->save(); $person->age( 31 ); $person->save(); # --- Reading my $other = Person->retrive( 616742 );
None at this moment.
Person->collection()
MongoDB collection class attribute. It contains the MongoDB::Collection associated with this entity.
my $id = $model->id(); my $current_id = $model->id( '12345' );
my $cursor = Person->find( { age => 30 }, {} );
Executes the mongo query returning a Mongol::Cursor object. Supports the same parameters as the find method definded in the MongoDB::Collection package.
my $model = Person->find( { name => 'John Doe' }, {} );
my $model = Person->retrieve( $id );
my $count = Person->count( { age => '30' }, {} );
my $bool = Person->exists( $id );
my $count = Person->delete( { age => { '$gt' => 30 } } );
$model->age( 35 ); $model->save();
$model->remove();
Person->drop();
Drops the MongoDB collection associated to this entity.
MongoDB::Collection
MooseX::ClassAttribute
To install Mongol, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mongol
CPAN shell
perl -MCPAN -e shell install Mongol
For more information on module installation, please visit the detailed CPAN module installation guide.