Databases Reference
In-Depth Information
Remember, there are far more supported commands than just those listed earlier. Oth-
ers are documented as appropriate throughout the rest of the topic, and for the full list,
just run listCommands .
Capped Collections
We've already seen how normal collections in MongoDB are created dynamically and
automatically grow in size to fit additional data. MongoDB also supports a different
type of collection, called a capped collection , which is created in advance and is fixed
in size (see Figure 7-1 ). Having fixed-size collections brings up an interesting question:
what happens when we try to insert into a capped collection that is already full? The
answer is that capped collections behave like circular queues: if we're out of space, the
oldest document(s) will be deleted, and the new one will take its place (see Fig-
ure 7-2 ). This means that capped collections automatically age-out the oldest docu-
ments as new documents are inserted.
Certain operations are not allowed on capped collections. Documents cannot be re-
moved or deleted (aside from the automatic age-out described earlier), and updates
that would cause documents to move (in general updates that cause documents to grow
in size) are disallowed. By preventing these two operations, we guarantee that docu-
ments in a capped collection are stored in insertion order and that there is no need to
maintain a free list for space from removed documents.
Figure 7-1. New documents are inserted at the end of the queue
 
Search WWH ::




Custom Search