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…

  1. Execute the following to ensure you are in the test database:
    > use test
    
  2. 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'}) ...

Get MongoDB Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.