MongoDBRef
PHP Manual

MongoDBRef::create

(PECL mongo >= 0.9.0)

MongoDBRef::createCreates a new database reference

Descrição

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

If no database is given, the current database is used.

Parâmetros

collection

Collection name.

id

The _id field of the object to which to link.

database

Database name.

Valor Retornado

Returns the reference.

Exemplos

Exemplo #1 MongoDBRef::create() example

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

// save $address so it has an _id
$addresses->insert($address);

// create a reference
$ref MongoDBRef::create($addresses->name$address['_id']);

// set the field in $person
$person['address'] = $ref;
$people->save($person);
?>

Veja Também


MongoDBRef
PHP Manual