MongoDBx::AutoDeref - Automagically dereference MongoDB DBRefs lazily
version 1.110560
use MongoDB; #or omit this use MongoDBx::AutoDeref; my $connection = MongoDB::Connection->new(); my $database = $connection->get_database('foo'); my $collection = $database->get_collection('bar'); my $doc1 = { baz => 'flarg' }; my $doc2 = { yarp => 'floop' }; my $id = $collection->insert($doc1); $doc2->{dbref} = {'$db' => 'foo', '$ref' => 'bar', '$id' => $id }; my $id2 = $collection->insert($doc2); my $fetched_doc2 = $collection->find_one({_id => $id2 }); my $fetched_doc1 = $fetched_doc2->{dbref}->fetch; # $fetched_doc1 == $doc1
Using Mongo drivers from other languages and miss driver support for expanding DBRefs? Then this module is for you. Simple 'use' it to have this ability added to the core MongoDB driver.
Please read more about DBRefs: http://www.mongodb.org/display/DOCS/Database+References
If more information is necessary on the guts, please see MongoDBx::AutoDeref::LookMeUp
Upon use (or require+import), this class method will load MongoDB (if it isn't already loaded), and alter the metaclasses for MongoDB::Cursor and MongoDB::Collection. Internally, everything is cursor driven so the result returned is ultimately from the "next" in MongoDB::Cursor method. So this method is advised to apply the MongoDBx::AutoDeref::LookMeUp sieve to the returned result which replaces all DBRefs with MongoDBx::AutoDeref::DBRef objects. When doing updates and inserts back using MongoDB::Collection, the inflated objects will be deflated back into DBRefs.
Nicholas R. Perez <nperez@cpan.org>
This software is copyright (c) 2010 by Nicholas R. Perez <nperez@cpan.org>.
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 MongoDBx::AutoDeref, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MongoDBx::AutoDeref
CPAN shell
perl -MCPAN -e shell install MongoDBx::AutoDeref
For more information on module installation, please visit the detailed CPAN module installation guide.