There are two types of collections normal collection and capped collection
above command creates capped collection with below details
capped collection name : my_cap_col1
fixed size : 100000 byes
- In comparison to the normal collection, capped collections are created in advance and are fixed in size
- Normal collections are created dynamically and automatically grow in size to fit extra data
- These capped collections are designed to consume less space and are rotating that means once allocated space is full, it will start writing from older documents again.
- Below operations are not allowed on a capped collection
- Documents can not be removed
- Updates that make documents to grow in size are not allowed
Capped collections can not be sharded
Creating Capped collection
As discussed above, capped collection needs to be created explicitly, we will discuss commands for the same
>
db.createCollection("my_cap_col1",
...
{"capped" : true, "size":100000});
{
"ok" : 1 }
>
capped collection name : my_cap_col1
fixed size : 100000 byes
same way capped collection can be created with limit on number of documents
for example
Once capped collections are created, it can not be modified, it must be dropped and recreated with desired parameters
Converting normal collection to capped collection
There is no way to convert capped collection to normal collection
for example
>
db.createCollection("my_cap_col2",
... {"capped":true, "size" :
100000, "max" : 100});
{ "ok" : 1 }
> show collections;
my_cap_col1
my_cap_col2
Once capped collections are created, it can not be modified, it must be dropped and recreated with desired parameters
Converting normal collection to capped collection
> db.runCommand({"convertToCapped":
"techno_col",size:10000});
{ "ok" : 1 }
>
There is no way to convert capped collection to normal collection