MongoDBRef::create

(PECL mongo >= 0.9.0)

MongoDBRef::create锟斤拷锟斤拷一锟斤拷锟铰碉拷锟斤拷锟捷匡拷锟斤拷锟斤拷

说锟斤拷

public static MongoDBRef::create ( string $collection , mixed $id [, string $database ] ) : array

锟斤拷锟矫伙拷锟街革拷锟斤拷锟斤拷菘猓拷锟斤拷锟绞癸拷玫锟角帮拷锟斤拷菘狻�

锟斤拷锟斤拷

collection

锟斤拷锟斤拷锟斤拷锟狡o拷锟斤拷锟斤拷锟斤拷锟斤拷锟捷匡拷锟斤拷锟斤拷锟斤拷

id

要锟斤拷锟接的讹拷锟斤拷锟� _id 锟街段★拷

database

锟斤拷锟捷匡拷锟斤拷锟斤拷

锟斤拷锟斤拷值

锟斤拷锟斤拷锟斤拷锟矫★拷

锟斤拷锟斤拷

Example #1 MongoDBRef::create() 锟斤拷锟斤拷

锟斤拷锟斤拷锟斤拷锟轿拷牡锟斤拷锟斤拷锟斤拷锟揭伙拷锟� addresses 锟斤拷锟斤拷锟捷匡拷锟斤拷锟矫★拷 MongoCollection::getName() 锟斤拷锟斤拷锟斤拷锟截硷拷锟较碉拷锟斤拷锟街o拷锟斤拷锟斤拷锟斤拷锟斤拷锟捷匡拷锟斤拷锟斤拷锟斤拷

<?php
$addresses 
$db->addresses;
$people $db->people;

// 锟斤拷锟斤拷 $address锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷 _id
$addresses->insert($address);

// 锟斤拷锟斤拷锟斤拷锟斤拷
$ref MongoDBRef::create($addresses->getName(), $address['_id']);

//锟斤拷锟斤拷 $person 锟斤拷锟斤拷侄锟�
$person['address'] = $ref;
$people->save($person);
?>

锟轿硷拷