Entities::Backend::MongoDB - Stores all Entities data in a MongoDB database.


version 0.5


        use Entities;
        use Entities::Backend::MongoDB;

        # see synopsis at L<Entities>


This backend for the Entities user management and authorization system stores all entities and relations between them in a MongoDB database, using the MongoDB module. This is a powerful, fast backend that gives you all the features of MongoDB. This is the only backend right now that can be used in production environments.

A big advantage of using this backend is that there is no setup work necessary. Just make sure your MongoDB daemon is running, and this backend will automatically create the database and necessary collections.


The following method are unique to this backend only.

new( [ host => 'localhost', port => 27017, db_name => 'entities' ] )

Creates a new instance of this module. Can receive the hostname of the server running the MongoDB daemon, the port on that host where the daemon is listening, and the name of the database to use. None of these parameters is required, host will default to 'localhost', port will default to 27017 (the default MongoDB port) and db_name will default to 'entities'.


Returns the host name or IP of the MongoDB server.


Returns the port number on the host where the MongoDB server listens.


Returns the name of the database into which all data is saved.

db( [$db_obj] )

Returns the MongoDB::Database object used for actually storing and retrieving data. If a MongoDB::Database object is provided, it will replace the current object.

to_hash( $obj )

Receives an entity object (either user, action, role, feature, plan or customer) and turns it into a hash-ref that can be saved in the database.


The following methods implement the methods that the Entities::Backend Moose role requires backend classes to implement. See the documentation of that role for more information on these methods.

get_user_from_id( $user_id )

get_user_from_name( $username )

get_role( $role_name )

get_customer( $customer_name )

get_plan( $plan_name )

get_feature( $feature_name )

get_action( $action_name )

save( $obj )


The following list documents any method modifications performed through the magic of Moose.


This method is automatically invoked immediately after the new() method is invoked. It is used to initiate the connection to the MongoDB database and store it in the object.


Entities, Entities::Backend, Entities::Backend::Memory, MongoDB.


Ido Perlmuter, <ido at ido50 dot net>


Please report any bugs or feature requests to bug-entities 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 Entities::Backend::MongoDB

You can also look for information at:


Copyright 2010-2013 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.