Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mongodbref(3) [php man page]

MONGODBREF(3)								 1							     MONGODBREF(3)

The MongoDBRef class

INTRODUCTION
This class can be used to create lightweight links between objects in different collections. Motivation: Suppose we need to refer to a document in another collection. The easiest way is to create a field in the current document. For example, if we had a "people" collection and an "addresses" collection, we might want to create a link between each person document and an address document: Example #1 Linking documents <?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 $addresses->insert($myAddress); // save a person with a reference to the address $me = array("name" => "Fred", "address" => $myAddress['_id']); $people->insert($me); ?> Then, later on, we can find the person's address by querying the "addresses" collection with the MongoId we saved in the "people" collec- tion. Suppose now that we have a more general case, where we don't know which collection (or even which database) contains the referenced docu- ment. MongoDBRef is a good choice for this case, as it is a common format that all of the drivers and the database understand. If each person had a list of things they liked which could come from multiple collections, such as "hobbies", "sports", "books", etc., we could use MongoDBRefs to keep track of what "like" went with what collection: 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 $people->insert(array("name" => "Fred", "likes" => array($trainRef, $soccerRef))); ?> Database references can be thought of as hyperlinks: they give the unique address of another document, but they do not load it or automat- ically follow the link/reference. A database reference is just a normal associative array, not an instance of MongoDBRef, so this class is a little different than the other data type classes. This class contains exclusively static methods for manipulating database references. CLASS SYNOPSIS
MongoDBRef MongoDBRef Methods o publicstatic array MongoDBRef::create (string $collection, mixed $id, [string $database]) o publicstatic array MongoDBRef::get (MongoDB $db, array $ref) o publicstatic bool MongoDBRef::isRef (mixed $ref) SEE ALSO
MongoDB core docs on databases references. PHP Documentation Group MONGODBREF(3)

Check Out this Related Man Page

MONGOEXCEPTION(3)							 1							 MONGOEXCEPTION(3)

The MongoException class

INTRODUCTION
Default Mongo exception. This covers a bunch of different error conditions that may eventually be moved to more specific exceptions, but will always extend Mon- goException. o The MongoSomething object has not been correctly initialized by its constructor Code: 0 Probably your Mongo object is not con- nected to a database server. o zero-length keys are not allowed, did you use $ with double quotes? Code: 1 You tried to save "" as a key. You generally should not do this. "" can mess up subobject access and is used by MongoDB internally. However, if you really want, you can set mongo.allow_empty_keys to true in your php.ini file to override this sanity check. If you override this, it is highly recommended that you set error checking to strict to avoid string interpolation errors. o '.' not allowed in key: <key> Code: 2 You attempted to write a key with '.' in it, which is prohibited. o insert too large: <size>, max: <max> Code: 3 You're attempting to send too much data to the database at once: the database will only accept inserts up to a certain size (currently 16 MB). o no elements in doc Code: 4 You're attempting to save a document with no fields. o size of BSON doc is <size> bytes, max <max>MB Code: 5 You're attempting to save a document that is larger than MongoDB can save. o no documents given Code: 6 You're attempting to batch insert an empty array of documents. o MongoCollection::group takes an array, object, or MongoCode key Code: 7 Wrong type parameter send to MongoCollection.group(3). o field names must be strings Code: 8 You should format field selectors as array("field1" => 1, "field2" => 1, ..., "fieldN" => 1). o invalid regex Code: 9 The regex passed to MongoRegex is not of the correct form. o MongoDBRef::get: $ref field must be a string Code: 10 o MongoDBRef::get: $db field must be a string Code: 11 o non-utf8 string: <str> Code: 12 This error occurs if you attempt to send a non-utf8 string to the database. All strings going into the database should be UTF8. See php.ini options for the transition option of quieting this exception. o mutex error: <err> Code: 13 The driver uses mutexes for synchronizing requests and responses in multithreaded environments. This is a fairly serious error and may not have a stack trace. It's unusual and should be reported to maintainers with any system information and steps to reproduce that you can provide. o index name too long: <len>, max <max> characters Code: 14 Indexes with names longer than 128 characters cannot be created. If you get this error, you should use MongoCollection.ensureIndex(3)'s "name" option to create a shorter name for your index. CLASS SYNOPSIS
MongoException MongoExceptionextends Exception PHP Documentation Group MONGOEXCEPTION(3)
Man Page