In this recipe, we will demonstrate the process to convert a normal collection to a capped collection.
Refer to the Single node installation of MongoDB recipe in Chapter 1, Installing and Starting the MongoDB Server, and start a single instance of Mongo. This is the only prerequisite for this recipe. Start a Mongo shell and connect to the started server.
Execute the following command to ensure that 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 query in the Mongo shell and execute it:
for(i = 1 ; i <= 100 ; i++) { db.normalCollection.insert({'i': i, val :'Some Text Content'}) }
Query the collection, as follows, to confirm if it contains the data:
> db.normalCollection.find()
Now query the
system.namespaces
collection as follows, and note the result document:> db.system.namespaces.find({name : 'test.normalCollection...