The "$id" has to be a
new MongoId("...")
in PHP driver!
Ref:
array(
"$ref" => "other_collection",
"$id" => new MongoId("the_referenced_dataobject_id")
)
MongoCollection::getDBRef
(PECL mongo >=0.9.0)
MongoCollection::getDBRef — Fetches the document pointed to by a database reference
Описание
public array MongoCollection::getDBRef
( array $ref
)
Параметри
- ref
-
A database reference.
Връщани стойности
Returns the database document pointed to by the reference.
Примери
Example #1 MongoCollection::createDBRef() example
<?php
$playlists = $db->selectCollection('playlists');
$myList = $playlists->findOne(array('username' => 'me'));
// fetch each song in the playlist
foreach ($myList['songlist'] as $songRef) {
$song = $playlists->getDBRef($songRef);
echo $song['title'] . "\n";
}
?>
Примерът по-горе ще изведе нещо подобно на:
Dazed and Confused Ma na ma na Bohemian Rhapsody
manuel at dziubas dot de
17-Apr-2011 10:10
