MongoCollection::getDBRef

(PECL mongo >=0.9.0)

MongoCollection::getDBRefFetches the document pointed to by a database reference

Descrierea

public MongoCollection::getDBRef ( array $ref ) : array

Parametri

ref

A database reference.

Valorile întoarse

Returns the database document pointed to by the reference.

Exemple

Example #1 MongoCollection::getDBRef() example

<?php

$playlists 
$db->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";
}

?>

Exemplul de mai sus va afișa ceva similar cu:

Dazed and Confused
Ma na ma na
Bohemian Rhapsody

In the above example each $songRef looks something like the following:
    Array
    (
        [$ref] => songs
        [$id] => 49902cde5162504500b45c2c
    )
    

A se vedea și

add a note add a note

User Contributed Notes 1 note

up
0
manuel at dziubas dot de
13 years ago
The "$id" has to be a

new MongoId("...")

in PHP driver!

Ref:
array(
  "$ref" => "other_collection",
  "$id" => new MongoId("the_referenced_dataobject_id")
)
To Top