Book Image

MongoDB Cookbook

By : Amol Nayak
Book Image

MongoDB Cookbook

By: Amol Nayak

Overview of this book

<p>MongoDB is a high-performance and feature-rich NoSQL database that forms the backbone of numerous complex development systems. You will certainly find the MongoDB solution you are searching for in this book.</p> <p>Starting with how to initialize the server in three different modes with various configurations, you will then learn a variety of skills including the basics of advanced query operations and features in MongoDB and monitoring and backup using MMS. From there, you can delve into recipes on cloud deployment, integration with Hadoop, and improving developer productivity. By the end of this book, you will have a clear idea about how to design, develop, and deploy MongoDB.</p>
Table of Contents (17 chapters)
MongoDB Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Converting a normal collection to a capped collection


In this recipe, we will demonstrate the process to convert a normal collection to a capped collection.

Getting ready

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.

How to do it…

  1. Execute the following command to ensure that 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 query in the Mongo shell and execute it:

    for(i = 1 ; i <= 100 ; i++) {
      db.normalCollection.insert({'i': i, val :'Some Text Content'})
    }
    
  3. Query the collection, as follows, to confirm if it contains the data:

    > db.normalCollection.find()
    
  4. Now query the system.namespaces collection as follows, and note the result document:

    > db.system.namespaces.find({name : 'test.normalCollection...