MongoDBRef::create

(PECL mongo >= 0.9.0)
Creates a new database reference
public static array MongoDBRef::create ( string $collection, mixed $id [, string $database ] )

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

Parameters:
collection

Collection name (without the database name).

id

The _id field of the object to which to link.

database

Database name.

Returns:

Returns the reference.

Examples:
MongoDBRef::create() example

This creates a database reference to a document in the addresses collection. The MongoCollection::getName() function returns the name of the collection (not including the database name).

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

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

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

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

See also:

MongoDB::createDBRef() -

MongoCollection::createDBRef() -

doc_php
2016-02-24 16:20:51
Comments
Leave a Comment

Please login to continue.