Database Reference
In-Depth Information
changing a string field from “foo” to “bar” is fine, but changing from “foo” to
“foobar” is not allowed. Finally, documents cannot be deleted from a capped
collection. They are removed as they “age out,” but there is no way to delete
a specific document.
Converting a Collection to A Capped
Collection
It is possible to convert a normal collection to a capped collection. The
command is not part of the standard set of operations, but you can
access it via the runCommand method. For example, to convert the
first collection to a capped collection holding 1MB of data use:
> db.runCommand({"convertToCapped": "first", size:
1024*1024});
Take care when running this command as it takes a global write lock.
All write operations on the database will block until the conversion has
been completed. Never attempt it on a server in rotation.
Capped collections can be queried in the usual way, but more often a
“tailable cursor” is used to read data in the order it was inserted. This is
more or less equivalent to using the Unix tail -f command.
Themostcommonusecasecitedforcappedcollectionsisasadatatransport
mechanism. In the architectures used in this topic, it would replace either
Kafka or Flume in the data transport layer. However, capped collections
suffer from a major flaw as a data transport tool because the collection
is capped to a size, not to a time. As discussed in Chapter 5, “Processing
Streaming Data,” this has failure modes that are very difficult to monitor.
As such, using MongoDB's capped collections for this application is not
recommended.
Basic Indexing
The primary role of a collection is to maintain a set of indexes common
to a group of documents. The assumption is that the indexes represent
Search WWH ::




Custom Search