MongoDB Documentation, Release 3.0.4 To prevent this error, create your secondary from a snapshot of one of the other up-to-date members of the replica set. Follow our tutorial on filesystem snapshots (page 243) to seed your new secondary. Seeding the secondary with a filesystem snapshot is the only way to guarantee the primary and secondary binary files are compatible. MongoDB Cloud Manager Backup snapshots are insufficient in this situation since you need more than the content of the secondary to match the primary. • You cannot delete documents from a capped collection. To remove all documents from a collection, use the drop() method to drop the collection. • You cannot shard a capped collection. • Capped collections created after 2.2 have an _id field and an index on the _id field by default. Capped collections created before 2.2 do not have an index on the _id field by default. If you are using capped collections with replication prior to 2.2, you should explicitly create an index on the _id field. Warning: If you have a capped collection in a replica set outside of the local database, before 2.2, you should create a unique index on _id . Ensure uniqueness using the unique: true option to the createIndex() method or by using an ObjectId for the _id field. Alternately, you can use the autoIndexId option to create when creating the capped collection, as in the Query a Capped Collec- tion (page 210) procedure. • Use natural ordering to retrieve the most recently inserted elements from the collection efficiently. This is (somewhat) analogous to tail on a log file. • The aggregation pipeline operator $out cannot write results to a capped collection. Procedures Create a Capped Collection You must create capped collections explicitly using the createCollection() method, which is a helper in the mongo shell for the create command. When creating a capped collection you must specify the maximum size of the collection in bytes, which MongoDB will pre-allocate for the collection. The size of the capped collection includes a small amount of space for internal overhead. db.createCollection( "log", { capped: true , size: 100000 } ) If the size field is less than or equal to 4096, then the collection will have a cap of 4096 bytes. Otherwise, MongoDB will raise the provided size to make it an integer multiple of 256. Additionally, you may also specify a maximum number of documents for the collection using the max field as in the following document: db.createCollection("log", { capped : true , size : 5242880, max : 5000 } ) Important: The size argument is always required, even when you specify max number of documents. MongoDB will remove older documents if a collection reaches the maximum size limit before it reaches the maximum document count. See createCollection() and create . Query a Capped Collection If you perform a find() on a capped collection with no ordering specified, MongoDB guarantees that the ordering of results is the same as the insertion order. 210 Chapter 5. Administration