MongoDB::createDBRef

(PECL mongo >=0.9.0)

MongoDB::createDBRef锟斤拷锟斤拷锟斤拷锟捷匡拷锟斤拷锟斤拷

说锟斤拷

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

锟斤拷锟斤拷锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷锟斤拷锟斤拷菘锟斤拷锟斤拷玫锟斤拷锟秸癸拷涌冢锟斤拷慰锟�MongoDBRef锟斤拷

锟斤拷锟斤拷

collection

锟斤拷锟捷匡拷锟斤拷锟斤拷指锟斤拷募锟斤拷锟�

document_or_id

锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� _id 锟街段斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷ID锟斤拷锟斤拷锟斤拷锟揭伙拷锟� MongoId 锟斤拷锟斤拷锟津单憋拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷为锟斤拷锟斤拷ID锟斤拷

锟斤拷锟斤拷值

锟斤拷锟斤拷一锟斤拷锟斤拷锟捷匡拷锟斤拷锟斤拷锟斤拷锟介。

锟斤拷锟揭伙拷锟矫伙拷锟� _id 锟街段碉拷锟斤拷锟斤拷锟斤拷为 document_or_id 锟斤拷锟斤拷锟斤拷NULL锟结被锟斤拷锟截★拷

锟斤拷锟斤拷

Example #1 MongoDB::createDBRef()实锟斤拷

锟斤拷示锟斤拷未映锟斤拷锟斤拷写锟斤拷锟斤拷牡锟斤拷锟斤拷锟斤拷菘锟斤拷锟斤拷谩锟�

<?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
             (
             )

     )
     

锟斤拷锟斤拷$ref锟斤拷锟皆憋拷锟斤拷锟芥到锟斤拷一锟斤拷锟侥碉拷锟叫o拷锟斤拷锟斤拷之锟斤拷通锟斤拷 MongoDB::getDBRef()锟斤拷MongoCollection::getDBRef() 锟斤拷锟斤拷取锟截★拷

Example #2 MongoDB::createDBRef()实锟斤拷

锟斤拷示锟斤拷锟斤拷诔锟斤拷锟斤拷锟街低拷锟揭伙拷锟絠d锟斤拷锟斤拷锟斤拷锟捷匡拷锟斤拷锟矫★拷

<?php

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