MongoDBRef 锟斤拷

(PECL mongo >=0.9.0)

锟斤拷锟�

锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟节达拷锟斤拷锟斤拷同锟斤拷锟斤拷锟叫讹拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟接★拷

Motivation锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟揭拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷械锟斤拷牡锟斤拷锟斤拷锟津单的凤拷锟斤拷锟斤拷锟节碉拷前锟侥碉拷锟叫达拷锟斤拷一锟斤拷锟街段★拷锟斤拷锟界,锟斤拷 "people" 锟斤拷锟较猴拷 "addresses" 锟斤拷锟较o拷锟斤拷锟斤拷锟斤拷要"锟斤拷锟斤拷"每锟斤拷 person 锟酵讹拷应锟斤拷 address 锟斤拷锟斤拷锟皆o拷

Example #1 锟斤拷锟斤拷锟侥碉拷

<?php

$people 
$db->people;
$addresses $db->addresses;

$myAddress = array("line 1" => "123 Main Street"
    
"line 2" => null,
    
"city" => "Springfield",
    
"state" => "Vermont",
    
"country" => "USA");

// save the address 锟斤拷锟斤拷address锟侥碉拷
$addresses->insert($myAddress);

// save a person with a reference to the address 锟斤拷锟斤拷一锟斤拷people锟斤拷锟斤拷锟斤拷锟秸才碉拷address
$me = array("name" => "Fred""address" => $myAddress['_id']);
$people->insert($me);

?>

然锟斤拷锟斤拷锟角匡拷锟皆o拷锟窖憋拷锟斤拷锟斤拷 "people" 锟斤拷锟斤拷锟叫碉拷 MongoId 锟斤拷为锟斤拷锟斤拷锟斤拷锟斤拷询 "address" 锟斤拷锟较o拷锟斤拷锟斤拷取一锟斤拷锟剿的碉拷址锟斤拷

锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷懈锟斤拷锟揭伙拷锟斤拷缘牡锟斤拷锟斤拷锟斤拷锟斤拷锟角诧拷知锟斤拷锟侥革拷锟斤拷锟较o拷锟斤拷锟斤拷锟斤拷锟捷库)锟叫帮拷锟斤拷锟斤拷锟斤拷要锟斤拷锟矫碉拷锟侥碉拷锟斤拷 MongoDBRef 锟斤拷锟角革拷锟斤拷选锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷通锟矫的革拷式锟斤拷锟斤拷锟叫碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟捷库都锟斤拷锟皆达拷锟斤拷锟斤拷锟斤拷

锟斤拷锟矫匡拷锟�"锟斤拷"锟斤拷一系锟叫癸拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷系锟斤拷锟较拷锟斤拷锟斤拷绨拷谩锟斤拷硕锟斤拷锟斤拷榧拷龋锟斤拷锟斤拷强锟斤拷锟斤拷锟斤拷锟斤拷锟� MongoDBRef 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷每一锟斤拷 锟斤拷锟斤拷 锟斤拷锟斤拷锟侥革拷锟斤拷锟较o拷

Example #2 Creating MongoDBRef links

<?php

$people 
$db->selectCollection("people");

// model trains are in the "hobbies" collection
$trainRef MongoDBRef::create("hobbies"$modelTrains['_id']);
// soccer is in the "sports" collection
$soccerRef MongoDBRef::create("sports"$soccer['_id']);

// now we'll know what collections the items in the "likes" array came from when
// we retrieve this document
//  # 锟斤拷锟节碉拷锟斤拷锟角讹拷取锟斤拷锟斤拷牡锟斤拷锟绞憋拷颍涂锟斤拷锟街拷锟�"likes"锟街讹拷锟斤拷锟斤拷锟斤拷锟皆拷胤直锟斤拷锟斤拷锟斤拷母锟斤拷锟斤拷锟斤拷恕锟�
$people->insert(array("name" => "Fred""likes" => array($trainRef$soccerRef)));

?>

锟斤拷锟捷匡拷锟斤拷锟矫匡拷锟皆憋拷锟斤拷锟轿拷锟斤拷锟斤拷樱锟斤拷锟斤拷锟街革拷锟斤拷锟揭伙拷锟斤拷牡锟斤拷锟轿ㄒ伙拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷远锟斤拷锟饺★拷锟斤拷吒锟斤拷锟斤拷锟斤拷谩锟斤拷锟斤拷印锟斤拷锟�

一锟斤拷锟斤拷锟捷匡拷锟斤拷锟矫斤拷锟斤拷锟斤拷一锟斤拷锟斤拷通锟斤拷锟斤拷锟斤拷锟介,锟斤拷锟斤拷 MongoDBRef 锟斤拷实锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟叫╋拷锟酵拷锟斤拷锟斤拷锟斤拷只锟斤拷锟斤拷锟斤拷态锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟矫★拷 锟斤拷注锟斤拷锟斤拷锟斤拷锟斤拷锟轿碉拷锟斤拷思锟斤拷锟斤拷为 1.一锟斤拷锟斤拷锟捷匡拷锟斤拷锟斤拷锟诫超锟斤拷锟斤拷锟斤拷锟狡o拷锟斤拷锟狡★拷删锟斤拷锟斤拷锟睫改等诧拷锟斤拷锟斤拷锟斤拷影锟斤拷原锟斤拷锟斤拷锟侥碉拷锟斤拷 2.锟斤拷取锟斤拷锟斤拷锟斤拷每锟斤拷缘锟街革拷锟斤拷锟侥碉拷锟斤拷位锟矫o拷锟斤拷锟斤拷锟斤拷知锟斤拷锟侥碉拷锟斤拷锟斤拷锟捷o拷要锟街讹拷锟斤拷锟斤拷锟矫★拷 3.锟斤拷锟�"锟斤拷锟斤拷"锟斤拷锟芥到Mongo锟斤拷时锟斤拷锟斤拷锟斤拷锟酵拷锟斤拷锟�

锟斤拷摘要

MongoDBRef {
/* 锟斤拷锟斤拷 */
public static create ( string $collection , mixed $id [, string $database ] ) : array
public static get ( MongoDB $db , array $ref ) : array
public static isRef ( mixed $ref ) : bool
}

锟轿硷拷

MongoDB 锟劫凤拷锟斤拷锟斤拷锟侥碉拷 » databases references.

Table of Contents

  • MongoDBRef::create — 锟斤拷锟斤拷一锟斤拷锟铰碉拷锟斤拷锟捷匡拷锟斤拷锟斤拷
  • MongoDBRef::get — 锟斤拷取锟斤拷锟斤拷锟斤拷指锟斤拷亩锟斤拷锟�
  • MongoDBRef::isRef — 锟斤拷锟斤拷锟斤拷锟斤拷欠锟轿拷锟斤拷菘锟斤拷锟斤拷锟�