עידו פרלמוטר (Ido Perlmuter) > MongoDBx-Class > MongoDBx::Class::Connection

Download:
MongoDBx-Class-1.030002.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 1.030002   Source  

NAME ^

MongoDBx::Class::Connection - A connection to a MongoDB server

VERSION ^

version 1.030002

EXTENDS ^

MongoDB::Connection

SYNOPSIS ^

        # connect to a MongoDB server
        my $conn = $mongodbx->connect(host => '10.10.10.10', port => 27017);

        # the connection object is automatically saved to the 'conn'
        # attribute of the L<MongoDBx::Class> object (C<$mongodbx> above)

        $conn->get_database('people');

DESCRIPTION ^

MongoDBx::Class::Connection extends MongoDB::Connection. This class provides the document expansion and collapsing methods that are used internally by other MongoDBx::Class classes.

Note that a MongoDBx::Class object can only have one connection at a time. Connection is only made via the connect() method in MongoDBx::Class.

ATTRIBUTES ^

Aside for attributes provided by MongoDB::Connection, the following special attributes are added:

namespace

A string representing the namespace of document classes to load (e.g. MyApp::Schema). This is a required attribute (automatically received from the MongoDBx::Class object).

doc_classes

A hash-ref of document classes loaded. This is a required attribute (automatically received from the MongoDBx::Class object).

safe

A boolean value indicating whether to use safe operations (e.g. inserts and updates) by default - without the need to pass { safe => 1 } to relevant methods - or not. False by default.

is_backup

This boolean attribute is used by MongoDBx::Class::ConnectionPool objects that use a backup connection.

OBJECT METHODS ^

Aside from the methods provided by MongoDB::Connection, the following methods and modifications are added:

get_database( $name )

Returns a MongoDBx::Class::Database object representing the MongoDB database named $name.

safe( $boolean )

Overrides the current value of the safe attribute with a new boolean value.

expand( $coll_ns, \%doc )

Receives the full name (a.k.a namespace) of a collection (that is the database name, followed by a dot, and the collection name), and a document hash-ref, and attempts to expand it according to the '_class' attribute that should exist in the document. If it doesn't exist, the document is returned as is.

This is mostly used internally and you don't have to worry about expansion, it's done automatically.

collapse( \%doc )

Receives a document hash-ref and returns a collapsed version of it such that it can be safely inserted to the database. For example, you can't save an embedded document directly to the database, you need to convert it to a hash-ref first.

This method is mostly used internally and you don't have to worry about collapsing, it's done automatically.

INTERNAL METHODS ^

_collapse_val( $val )

AUTHOR ^

Ido Perlmuter, <ido at ido50.net>

BUGS ^

Please report any bugs or feature requests to bug-mongodbx-class at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MongoDBx-Class. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

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

        perldoc MongoDBx::Class::Connection

You can also look for information at:

SEE ALSO ^

MongoDBx::Class, MongoDB::Connection.

LICENSE AND COPYRIGHT ^

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 http://dev.perl.org/licenses/ for more information.

syntax highlighting: