MongoDB::createDBRef
Creates a database reference
&reftitle.description;
public arrayMongoDB::createDBRef
stringcollection
mixeda
This method is a flexible interface for creating database refrences (see
MongoDBRef).
&reftitle.parameters;
collection
The collection to which the database reference will point.
a
Object or _id to which to create a reference. If an object or
associative array is given, this will create a reference using
the _id field.
&reftitle.returnvalues;
Returns a database reference array.
&reftitle.examples;
MongoDB::createDBRef example
Example demonstrating how to programatically create a DB reference array from
a document.
articles;
$article = array(
'title' => 'Test article',
'description' => 'Test article description'
);
$articles->insert($article);
$ref = $db->createDBRef('articles', $article);
print_r($article);
print_r($ref);
?>
]]>
&example.outputs.similar;
Test article
[description] => Test article description
[_id] => MongoId Object
(
)
)
Array
(
[$ref] => articles
[$id] => MongoId Object
(
)
)
]]>
Now the $ref can be stored on another document and retrieved later with
MongoDB::getDBRef or MongoCollection::getDBRef.
MongoDB::createDBRef example
Example demonstrating how to programatically create a DB reference from just an id.
createDBRef('articles', $id);
?>
]]>