downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

MongoDBRef::create> <MongoBinData::__toString
Last updated: Fri, 13 Nov 2009

view this page in

The MongoDBRef class

Introdução

This class can be used to create lightweight links between objects in different collections.

Motivation: Suppose we need to refer to point to a document in another collection. The easiest way is to create a field in the current document, something like:

<?php

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

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

// save the address
$addresses->insert($myAddress);

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

?>

Suppose now that we have a more general case, where we don't know what collection contains the referenced document. MongoDBRef is a good choice for this case, as it is a common format that all of the drivers and the database understand.

<?php

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

$trainRef MongoDBRef::create("hobbies"$modelTrains['_id']);
$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
$people->insert(array("name" => "Fred""likes" => array($trainRef$soccerRef)));

?>

Sinopse da classe

MongoDBRef
MongoDBRef {
/* Methods */
public static array create ( string $ns , mixed $id )
public static array get ( MongoDB $db , array $ref )
public static boolean isRef ( array $ref )
}

Índice



add a note add a note User Contributed Notes
MongoDBRef
There are no user contributed notes for this page.

MongoDBRef::create> <MongoBinData::__toString
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites