MongoDB::createDBRef

(PECL mongo >=0.9.0)

MongoDB::createDBRefCreates a database reference

설명

public array MongoDB::createDBRef ( string $collection , mixed $document_or_id )

This method is a flexible interface for creating database refrences (see MongoDBRef).

인수

collection

The collection to which the database reference will point.

document_or_id

If an array or object is given, its _id field will be used as the reference ID. If a MongoId or scalar is given, it will be used as the reference ID.

반환값

Returns a database reference array.

If an array without an _id field was provided as the document_or_id parameter, NULL will be returned.

예제

Example #1 MongoDB::createDBRef() example

Example demonstrating how to programatically create a DB reference array from a document.

<?php

$articles 
$db->articles;

$article = array(
 
'title' => 'Test article',
 
'description' => 'Test article description'
);

$articles->insert($article);
$ref $db->createDBRef('articles'$article);

print_r($article);
print_r($ref);
?>

위 예제의 출력 예시:

     Array
     (
         [title] => 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().

Example #2 MongoDB::createDBRef() example

Example demonstrating how to programatically create a DB reference from just an id.

<?php

$id 
= new MongoId('47cc67093475061e3d9536d2');
$ref $db->createDBRef('articles'$id);
?>
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top