NAME
Mongoose::Cookbook - recipes, recipes
VERSION
version 0.01_01
RECIPES
Here we go.
Connecting to more than one database
This is a work in progress. Right now this syntax is supported:
Mongoose->db( class=>'Person', db_name=>'mydbone', ... );
Mongoose->db( class=>'Address', db_name=>'mydbtwo', ... );
But this will most certainly change.
Preventing attributes from being stored
In case your class has attributes you don't want to store in the database.
package Person;
use Moose;
with 'Mongoose::Document';
has 'name' => ( is => 'rw', isa => 'Str', required => 1 );
has 'age' => ( is => 'rw', isa => 'Int', default => 40 );
has 'salary' => ( is => 'rw', isa => 'Int', traits => ['DoNotSerialize'] );
Package aliasing
To make a long package name shorter, use:
package My::Mumbo::Jumbo::Class;
with 'Mongoose::Document' => {
-as => 'Mumbo',
};
# then in your code
my $obj = Mumbo->find_one({ flavor=>'gum' })
print ref $obj;
# prints 'My::Mumbo::Jumbo::Class'
print $obj->isa('Mumbo')
# prints 1
Method aliasing
In case you don't want a find_one
or save
method polluting your class.
package BankAccount;
with 'Mongoose::Document' => {
-alias => { 'find_one' => '_find_one' },
-excludes => { 'find_one' },
};