NAME

MongoDBx::AutoDeref - Automagically dereference MongoDB DBRefs lazily

VERSION

version 1.110530

SYNOPSIS

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

DESCRIPTION

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

CLASS_METHODS

import

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.

AUTHOR

Nicholas R. Perez <nperez@cpan.org>

COPYRIGHT AND LICENSE

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.