update : 2015.11.03
php.shukuma.com검색:
|
The MongoDBRef class(PECL mongo >=0.9.0) 소개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 Then, later on, we can find the person's address by querying the "addresses" collection with the MongoId we saved in the "people" collection. Suppose now that we have a more general case, where we don't know which collection (or even which database) 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. 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 Database references can be thought of as hyperlinks: they give the unique address of another document, but they do not load it or automatically 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. 클래스 개요참고MongoDB core docs on » databases references. Table of Contents
|