Mongoose::Join - simple class relationship resolver
version 0.10
package Author; use Moose; with 'Mongoose::Document'; has 'articles' => ( is => 'rw', isa => 'Mongoose::Join[Article]' );
This module can be used to parameterize relationships between two Mongoose::Document classes. It should not be used for Mongoose::EmbeddedDocument classes.
Mongoose::Document
Mongoose::EmbeddedDocument
All object relationships are stored as reference $id arrays in the parent object, which translates into a performance hit when loading the parent class, but not as much as loading all objects at one as when using an ArrayRef.
$id
ArrayRef
Add (join) a Mongoose::Document object for later saving.
Saving the parent Mongoose::Document will save both.
my $author = Author->new; $author->articles->add( Article->new ); $author->save; # saves all objects
Delete from the relationship list.
my $author = Author->find_one; my $first_article = $author->articles->find_one; $author->articles->remove( $first_article );
Run a MongoDB find on the joint collection.
find
# searches for articles belonging to this collection my $cursor = $author->articles->find({ title=>'foo article' }); while( my $article = $cursor->next ) { ... }
Returns a Mongoose::Cursor.
Just like find, but with a find_one twist.
find_one
Same as find, but returns an ARRAY with all the results, instead of a cursor.
Run a MongoDB query on the joint collection.
query
Returns the MongoDB::Collection for the joint collection.
Return the collection name for the joint Mongoose::Document.
To install Mongoose, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mongoose
CPAN shell
perl -MCPAN -e shell install Mongoose
For more information on module installation, please visit the detailed CPAN module installation guide.