Database Reference
In-Depth Information
Database
Collections
Documents
Figure 3-1. The MongoDB database model
Now compare the MongoDB database model to a typical model for a relational database (see Figure 3-2 ).
Database
Tables
Rows
Figure 3-2. A typical relational database model
As you can see, the general structure is the same between the two types of databases; nevertheless, you do not
use them in even remotely similar manners. There are several types of collections in MongoDB. The default collection
type is expandable in size: the more data you add to it, the larger it becomes. It's also possible to define collections
that are capped . These capped collections can only contain a certain amount of data before the oldest document is
replaced by a newer document (you will learn more about these collections in Chapter 4).
Every collection in MongoDB has a unique name. This name should begin with a letter, or optionally,
an underscore ( _ ) when created using the createCollection function. The name can contain numbers and letters;
however, the $ symbol is reserved by MongoDB. Similarly, using an empty string (“ ”) is not allowed; the null character
cannot be used in the name and it cannot start with the “ system .” string. Generally, it's recommended that you keep
the collection's name simple and short (to around nine characters or so); however, the maximum number of allowed
characters in a collection name is 128. Obviously, there isn't much practical reason to create such a long name.
A single database has a default limit of 24,000 namespaces. Each collection accounts for at least two namespaces:
one for the collection itself and one more for the first index created in the collection. If you were to add more indexes per
collection, however, another namespace would be used. In theory, this means that each database can have up to 12,000
collections by default, assuming each collection only carries one index. However, this limit on the number of namespaces
can be increased by providing the nssize parameter when executing the MongoDB service application ( mongod ).
 
Search WWH ::




Custom Search