Catalyst::Model::MongoDB - MongoDB model class for Catalyst
version 0.13
# # Config # <Model::MyModel> host localhost port 27017 dbname mydatabase username myuser password mypass collectionname preferedcollection gridfs preferedgridfs </Model::MyModel> # # Usage # $c->model('MyModel')->db # returns MongoDB::MongoClient->get_database $c->model('MyModel')->db('otherdb') # returns ->otherdb $c->model('MyModel')->collection # returns ->mydatabase->preferedcollection $c->model('MyModel')->coll # the same... $c->model('MyModel')->c # the same... $c->model('MyModel')->c('otherdb.othercollection') # returns ->otherdb->othercollection $c->model('MyModel')->c('somecollection') # returns ->mydatabase->somecollection $c->model('MyModel')->gridfs # returns ->mydatabase->get_gridfs('preferedgridfs') $c->model('MyModel')->g # the same... $c->model('MyModel')->g('somegridfs') # returns ->mydatabase->get_gridfs('somegridfs') $c->model('MyModel')->g('otherdb.othergridfs') # returns ->otherdb->get_gridfs('othergridfs') $c->model('MyModel')->run(...) # returns ->mydatabase->run_command(...) $c->model('MyModel')->eval(...) # returns ->mydatabase->eval(...) $c->model('MyModel')->database_names # returns ->database_names $c->model('MyModel')->dbnames # the same...
This model class exposes MongoDB::MongoClient as a Catalyst model.
You can pass the same configuration fields as when you make a new MongoDB::MongoClient.
In addition you can also give a database name via dbname, a collection name via collectioname or a gridfs name via gridfsname.
If all three of username, password, and dbname are present, this class will authenticate via MongoDB::MongoClient->authenticate(). (See MongoDB::MongoClient for details).
username
password
dbname
List of databases.
List of collection names of the default database. You cant give other database names here, if you need this please do:
$c->model('MyModel')->db('otherdatabase')->collection_names
Gives back a MongoDB::Collection, you can also directly access other dbs collections, with "otherdb.othercollection". If no collectionname is given he uses the default collectionname given on config.
Gives back a MongoDB::GridFS. If no gridfsname is given, he uses the default gridfsname given on config.
Run a command via MongoDB::Database->run_command on the default database. You cant give other database names here, if you need this please do:
$c->model('MyModel')->db('otherdatabase')->run_command(...)
Eval code via MongoDB::Database->eval on the default database. You cant give other database names here, if you need this please do:
$c->model('MyModel')->db('otherdatabase')->eval(...)
Creates MongoDB::OID object
[re]authenticate after the initial connection, or authenticate to multiple databases within the same model.
IRC
Join #catalyst on irc.perl.org and ask for Getty.
Repository
http://github.com/singingfish/p5-catalyst-model-mongodb Pull request and additional contributors are welcome
Issue Tracker
http://github.com/singingfish/p5-catalyst-model-mongodb/issues
Torsten Raudssus <torsten@raudssus.de> http://www.raudssus.de/
This software is copyright (c) 2010 by Raudssus Social Software.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Catalyst::Model::MongoDB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Model::MongoDB
CPAN shell
perl -MCPAN -e shell install Catalyst::Model::MongoDB
For more information on module installation, please visit the detailed CPAN module installation guide.