Is it possible to get max size of capped collection in MongoDB, the same size you have specified during creation?
Asked
Active
Viewed 2,168 times
1
-
Check [this](https://groups.google.com/forum/#!topic/mongodb-user/-3fmsKwb4GA) – Deepak Biswal Oct 09 '14 at 06:57
2 Answers
3
Before V2.6, you can get it by
db.system.namespaces.findOne({name : namespace}).options.size;
// namesapce : <db>.<collection>
For V2.6+ (I test on V2.6.4), you can only get integral multiples of EXTENT_SIZE.
returnSize = Math.ceil(specifiedSize / EXTENT_SIZE) * EXTENT_SIZE
// for example, returnsize = Math.ceil(1 / 4096) * 4096 = 4096

Wizard
- 4,341
- 1
- 15
- 13
3
db.collectioname.stats()
will give you the max size. It will always be in multiple of 256
> db.createCollection( "log_cap2", { capped: true, size: 7500 } )
{ "ok" : 1 } >
db.log_cap2.stats() { "ns" : "test.log_cap2", "size" : 0, "count" : 0, "storageSize" : 4096, "capped" : true, "max" : -1, "maxSize" : 7680,
Even thou I gave size as 7500 it will allocate in multiples of 256
256*29 = 7424 256*30=7680

VIJ
- 1,516
- 1
- 18
- 34