@@ -5,60 +5,49 @@ Capped Collections
5
5
.. default-domain:: mongodb
6
6
7
7
:term:`Capped collections <capped collection>` are fixed-size
8
- collections that automatically overwrite their oldest entries when the
9
- fixed size is reached. Capped collections work in a way similar to
10
- circular buffers. The :term:`oplog.rs <oplog>`
11
- collection used in replication is an example of a capped collection.
8
+ collections that automatically overwrite their oldest documents when new
9
+ documents are inserted. Capped collections work in a way similar to
10
+ circular buffers. Once a collection fills its allocated space, it makes
11
+ room for new documents by deleting the oldest documents in the
12
+ collection.
12
13
13
- Capped collections automatically store documents in their insertion
14
- order. Once the collection's allocated space is fully used, newly added
15
- documents replace the oldest documents in the collection. The automatic
16
- replacement based on insertion order makes capped collections fast and
17
- efficient.
14
+ Capped collections are particularly fast and efficient for operations,
15
+ such as logging, that retrieve and delete documents based on insertion
16
+ order.
18
17
19
- You cannot increase the size of a document in a capped collection. You can update a
20
- document, but it must not grow in size.
18
+ Capped collections have the following behaviors:
21
19
22
- You cannot shard a capped collection.
23
-
24
- Capped Collection Use Cases
25
- ---------------------------
26
-
27
- The following are scenarios in which you might want to use a capped collection:
28
-
29
- - Logging
20
+ - Capped collections automatically store documents in their insertion
21
+ order. Therefore, no index is required to query on insertion order,
22
+ and capped collections incur no indexing overhead for this property.
30
23
31
- Capped collections provide a high-performance means for storing
32
- logging documents in the database. Inserting documents in an unindexed
33
- capped collection is close to the speed of logging to a
34
- filesystem. Additionally, with the built-in FIFO mechanism, you are
35
- not at risk of using excessive disk space for the logging .
24
+ - Capped collections guarantee that insertion order is identical to the
25
+ order on disk (:term:`natural order`) and do so by prohibiting updates
26
+ that increase document size. Capped collections only allow updates
27
+ that fit the original document size, which ensures a document does not
28
+ change its location on disk.
36
29
37
- - Automatic Maintaining of Insertion Order
30
+ - Capped collections automatically remove the oldest documents in the
31
+ collection without requiring scripts or explicit remove operations.
38
32
39
- Capped collections keep documents in their insertion order
40
- automatically, with no index being required for this property. The
41
- logging example above is a good example of a case where keeping items
42
- in order is important.
33
+ Capped collections provide a high-performance means for storing logging
34
+ information. Inserting documents in an unindexed capped collection is
35
+ close to the speed of logging to a filesystem. Additionally, the
36
+ built-in FIFO mechanism ensures logging does not use excessive disk
37
+ space.
43
38
44
- - Caching
39
+ Capped collections also provide a convenient way to cache known small
40
+ numbers of documents, such as cached computations of information. This
41
+ scenario would likely have more reads than writes and require an index.
45
42
46
- If you wish to cache a small number of documents in the database,
47
- perhaps cached computations of information, the capped tables provide
48
- a convenient mechanism for this. Note that for this application you
49
- typically use an index on the capped table as there are be more reads
50
- than writes.
51
-
52
- - Automatic Age Out
53
-
54
- If you know you want data to automatically "roll out" over time as it
55
- ages, a capped collection can be an easier way to support than writing
56
- manual removal via cron scripts. Ejection from the capped collection
57
- is also inexpensive compared to explicit remove operations.
43
+ The :term:`oplog.rs <oplog>` collection used in replication is an
44
+ example of a capped collection.
58
45
59
46
Recommendations and Restrictions
60
47
--------------------------------
61
48
49
+ You cannot shard a capped collection.
50
+
62
51
You may update the existing documents in the collection. However, the
63
52
documents must not grow in size. If they do, the update fails.
64
53
0 commit comments