Converting a normal collection to a capped collection
This recipe will demonstrate the process of converting a normal collection to a capped collection.
Getting ready
Look at the recipe Installing single node MongoDB in Chapter 1, Installing and Starting the Server and start a single instance of Mongo. That is the only prerequisite for this recipe. Start a mongo shell and connect to the started server.
How to do it…
Execute the following to ensure you are in the
test
database:> use test
Create a normal collection as follows. We will be adding 100 documents to it, type/copy the following code snippet on to the mongo shell and execute it. The command is as follows:
for(i = 1 ; i <= 100 ; i++) { db.normalCollection.insert({'i': i, val :'Some Text Content'}) }
Query the collection as follows to confirm it contains the data:
> db.normalCollection.find()
Now, query the collection
system.namespaces
as follows and note the result document:> db.system.namespaces.find({name : 'test.normalCollection...