MongoDB::DBRef - Native DBRef support
version v0.704.4.0
my $dbref = MongoDB::DBRef->new( db => 'my_db', ref => 'my_collection', id => 123 ); $coll->insert( { foo => 'bar', other_doc => $dbref } ); my $other_doc = $coll->find_one( { foo => 'bar' } )->{other_doc}->fetch;
This module provides support for database references (DBRefs) in the Perl MongoDB driver. A DBRef is a special embedded document which points to another document in the database. DBRefs are not the same as foreign keys and do not provide any referential integrity or constraint checking. For example, a DBRef may point to a document that no longer exists (or never existed.)
MongoDB::DBRef - A MongoDB database reference
Required. The database in which the referenced document lives. Either a MongoDB::Database object or a string containing the database name. The object will be coerced to string form.
Required. The collection in which the referenced document lives. Either a MongoDB::Collection object or a string containing the collection name. The object will be coerced to string form.
Required. The _id value of the referenced document. If the _id is an ObjectID, then you must use a MongoDB::OID object.
_id
Optional. A MongoDB::MongoClient object to be used to fetch the referenced document from the database. You must supply this attribute if you want to use the fetch method.
fetch
When you retrieve a document from MongoDB, any DBRefs will automatically be inflated into MongoDB::DBRef objects with the client attribute automatically populated.
MongoDB::DBRef
client
It is not necessary to specify a client if you are just making DBRefs to insert in the database as part of a larger document.
Optional. Check that the referenced database exists before trying to fetch a document from it. The default is 1. Set to 0 to disable checking.
1
0
Optional. Check that the referenced collection exists before trying to fetch a document from it. The default is 1. Set to 0 to disable checking.
Retrieve the referenced document from the database. If the document does not exist, you'll get back undef. You must populate the client attribute of the DBRef object in order to use this method. If there's no client, fetch will throw a fatal error.
undef
If verify_db or <verify_coll> are on, fetch will throw a fatal error if the database or collection concerned does not exist.
verify_db
David Golden <david.golden@mongodb.org>
Mike Friedman <friedo@mongodb.com>
Kristina Chodorow <kristina@mongodb.org>
Florian Ragwitz <rafl@debian.org>
This software is Copyright (c) 2014 by MongoDB, Inc..
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
To install MongoDB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MongoDB
CPAN shell
perl -MCPAN -e shell install MongoDB
For more information on module installation, please visit the detailed CPAN module installation guide.