When specifying the 'size' parameter for a capped collection, which of the following sizes from db.collection.stats() is capped to that size?
is it "size", "storageSize", "storageSize"+"totalIndexSize" or some other option?
Thanks!
According to the documentation:
Optional. Specifies a maximum size in bytes for a capped collection.
The size field is required for capped collections. If capped is false,
you can use this field to preallocate space for an ordinary
collection.
So I would assume it is storageSize.
This would also suggest it is limited on storageSize:
https://jira.mongodb.org/browse/SERVER-5615
Where Elliot says:
Indexes don't count within the capped size. The capped size is for
data alone. Indexes do use space, but b-trees have up to 50% extra
space because of balancing. The guarantee is that it'll never be more
than 50%.
Related
I haven't found any information about this.
How many documents can a single collection have in MongoDB before it is necessary to use sharding?
There is no limitation as you can see here:
If you specify a maximum number of documents for a capped collection using the max parameter to create, the limit must be less than 2^32 documents. If you do not specify a maximum number of documents when creating a capped collection, there is no limit on the number of documents.
#M-A.Fernandes has right.
I can only add this information:
Maximum Number of Documents Per Chunk to Migrate
MongoDB cannot move a chunk if the number of documents in the chunk exceeds either 250000 documents or 1.3 times the result of dividing the configured chunk size by the average document size. db.collection.stats() includes the avgObjSize field, which represents the average document size in the collection.
From docs: https://docs.mongodb.org/manual/reference/limits/
the maximum BSON document size is 16 megabytes.
I wonder how mongo checks this limit.
If I use WiredTiger and snappy compression, does it mean that I can put more data inside document until it reached 16Mb. Or Mongo calculates size of document in uncompressed state?
MongoDB enforces the 16MB limit even before passing the document to the storage engine, so no, you cannot use the compression to squeeze more data into the document.
Reference.
According to MongoDB documentation
The maximum document size helps ensure that a single document cannot
use excessive amount of RAM or, during transmission, excessive amount
of bandwidth. To store documents larger than the maximum size, MongoDB
provides the GridFS API.
What is the rationale for having auto index on _id field for capped collections by default? We can find in the docs that:
Without this indexing overhead, capped collections can support higher insertion throughput.
There was a post about capped collection insert performance and my own tests also show that for inserts capped collection without an index is the fastest option, then the normal collection goes, and the slowest option is capped collection with an index. So why auto index was added along with _id fields in version 2.2 if it hits performance while capped collections are proposed as fast alternatives to normal collections in certain scenarios?
Well, we certainly can't rule out benefits of _id in capped collection too. It help you and in fact required for replication.
MongoDB turned it on by default since deployment of MongoDB in replica set configuration is very normal now a days. You can find more information in documentation, please look for autoIndexId
I believe, the reason of slowness is Index, not _id field itself. So if your requirements warrant special needs, you can always disable auto index.
But...
you still need to supply _id field with zero (0) value.
e.g. 2 GB capped collection with auto index disabled.
db.createCollection("people", { capped: true, size: 2147483648, autoIndexId: false } )
I'm sure this trick will bring insertion speed back.
I currently have an environment of MongoDB, including Shards and Replicat Sets.
I was wondering if there is any way to limit the size of a database. I've read that I can limit the size with the --quota parameter, but this would globally limit the size of all the databases, while I'm trying to limit the size of certain databases to differnet sizes.
Thank You!
Use capped collection, which is applicable per collection within the database.
Refer to sample on MongoDB's doc http://docs.mongodb.org/manual/core/capped-collections/
db.createCollection("log", { capped : true, size : 5242880, max : 5000 } )
Where "log" is the collection name.
Do consider that in a capped collection, oldest document gets overwritten by new inserted document.
In MongoDB there is the maximum size of 16 MByte per document. Does this size limit include sub-documents?
In other words: Are the 16 MByte per document including its sub-documents, or is it 16 MByte per document and each sub-document counts as an own document?
Yes, this is 16MB limit for the whole structure, including sub-documents.
Keep in mind that what you call sub-documents, MongoDB sees as regular values. From its perspective, they are no different than, say, strings. Just values.