MongoDBx::Class::EmbeddedDocument(3) A MongoDBx::Class embedded (sub-)document role


version 1.030002


# create an embedded document class
package MyApp::Schema::PersonName;
use MongoDBx::Class::Moose; # use this instead of Moose
use namespace::autoclean;

with 'MongoDBx::Class::EmbeddedDocument';
has 'first_name' => (is => 'ro', isa => 'Str', required => 1, writer => 'set_first_name');

has 'middle_name' => (is => 'ro', isa => 'Str', predicate => 'has_middle_name', writer => 'set_middle_name');
has 'last_name' => (is => 'ro', isa => 'Str', required => 1, writer => 'set_last_name');
sub name {
my $self = shift;
my $name = $self->first_name;
$name .= ' '.$self->middle_name.' ' if $self->has_middle_name;
$name .= $self->last_name;
return $name;


MongoDBx::Class::EmbeddedDocument is a Moose role meant to be consumed by document classes representing embedded documents. These are documents that are entirely contained within parent MongoDB documents.

The role provides expanded embedded documents with some common attributes and useful methods.



The MongoDBx::Class::Collection object representing the MongoDB collection in which this embedded document is stored (more correctly, the collection in which the MongoDBx::Class::Document holding this embedded document is stored). This is a required attribute.


A string. The name of the document class of this embedded document. A required attribute.


The following methods are provided:


Returns the embedded document as a hash reference, without the _collection and _class attributes (if they exist).



Convenience shortcut for running "$embd_doc->_collection->_database".


Returns a list of names of all attributes the embedded document object has, minus '_collection' and '_class', sorted alphabetically.


Ido Perlmuter, "<ido at>"


Please report any bugs or feature requests to "bug-mongodbx-class at", or through the web interface at <>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

        perldoc MongoDBx::Class::EmbeddedDocument

You can also look for information at:


Copyright 2010-2014 Ido Perlmuter.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.