Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mongogridfs.storebytes(3) [php man page]

MONGOGRIDFS.STOREBYTES(3)						 1						 MONGOGRIDFS.STOREBYTES(3)

MongoGridFS::storeBytes - Stores a string of bytes in the database

SYNOPSIS
public mixed MongoGridFS::storeBytes (string $bytes, [array $metadata = array()], [array $options = array()]) DESCRIPTION
PARAMETERS
o $bytes - String of bytes to store. o $metadata - Other metadata fields to include in the file document. Note These fields may also overwrite those that would be created automatically by the driver, as described in the MongoDB core documentation for the files collection. Some practical use cases for this behavior would be to specify a custom chunkSize or _id for the file. o $options - An array of options for the insert operations executed against the chunks and files collections. See MongoCollection.insert(3) for documentation on these these options. RETURN VALUES
Returns the _id of the saved file document. This will be a generated MongoId unless an _id was explicitly specified in the $metadata param- eter. ERRORS
/EXCEPTIONS Throws MongoGridFSException if there is an error inserting into the chunks or files collections. EXAMPLES
Example #1 MongoGridFS.storeBytes(3) with additional metadata <?php $m = new MongoClient(); $gridfs = $m->selectDB('test')->getGridFS(); $bytes = 'abcdefghijklmnopqrstuvwxyz'; $id = $gridfs->storeBytes($bytes, array('_id' => 'alphabet')); $gridfsFile = $gridfs->get($id); var_dump($gridfsFile->file); ?> The above example will output something similar to: array(7) { ["_id"]=> string(8) "alphabet" ["uploadDate"]=> object(MongoDate)#7(0) { } ["length"]=> int(26) ["chunkSize"]=> int(262144) ["md5"]=> string(32) "c3fcd3d76192e4007dfb496cca67e13b" } SEE ALSO
MongoGridFS.put(3), MongoGridFS.storeFile(3), MongoGridFS.storeUpload(3), MongoDB core docs on GridFS. PHP Documentation Group MONGOGRIDFS.STOREBYTES(3)

Check Out this Related 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)
Man Page