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

Backing up and restoring data in Mongo using out-of-the box tools


In this recipe, we will look at some basic backup and restore operations using utilities such as mongodump and mongorestore to backup and restore files.

Getting ready

We will be starting a single instance of mongod. Refer to the Single node installation of MongoDB recipe in Chapter 1, Installing and Starting the MongoDB Server, to start a Mongo instance and connect to it from a Mongo shell. We will need some data to back up; if you already have some data in your test database that would be fine, else create some from the countries.geo.json file available in the code bundle, using the following command:

$ mongoimport  -c countries -d test --drop countries.geo.json

How to do it…

  1. With the data in the test database, execute the following command, assuming we want to export the data to a local directory called dump in the current directory:

    $ mongodump -o dump -oplog -h localhost -port 27017
    

    Verify that there is data in the dump directory...