Database Reference
In-Depth Information
Collections, created with the db.createCollection command are a
fairly loose concept in MongoDB. They are roughly analogous to tables,
but because MongoDB is schema-less there is no requirement that any
document inside of a collection resemble any other. Each document inside
of a collection is represented as a JSON object, and all documents have a
primary key field _ id that is usually an automatically generated ObjectId
object. However, the _ id field can be any type of object, except an Array ,
so long as it is unique within a collection. For the purposes of streaming
analysis, it is often useful to use this field as a form of compound primary
key to make it possible to update a specific document without having to
first query the collection to find the appropriate _ id value (or use a more
complicated update query).
Documents may not contain fields that start with $ . This character is
reserved for special objects in a MongoDB document, most commonly a
DBRef object that allows MongoDB documents to be linked together. These
objects are JSON objects containing $ref , $id , and, optionally, $db fields.
The $id field identifies the value of the _id field of the target document;
the $ref field identifies the target collection; and the $db field identifies
the target database if it is different than the current database. For example,
a reference to a document in the first collection might look like this:
{$ref:"first",$id:ObjectId("5126bc054aed4daf9e2ab772"),$db:"mine"}
Although documents in collections can be highly nested, a document can
be at most 16MB in size. This limitation is largely arbitrary on the part of
MongoDB's developers, but they are correct in their assertion that very large
documents should be a warning sign during data modeling.
Capped Collections
MongoDB supports creating new collections as a “capped collection.” These
are fixed-size collections designed to support high-throughput operations.
For example, MongoDB uses capped collections to implement the operation
log for its own replication strategy.
Capped collections implement a FIFO queue with a few restrictions. First,
capped collections may not be sharded. Among other things, it would make
it difficult to maintain the FIFO queue. Second, while documents written to
acappedcollectionmaybechanged,theymaynotgrowinsize.Forexample,
Search WWH ::




Custom Search