Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

MongoDB Cookbook - Second Edition
MongoDB Cookbook - Second Edition
MongoDB Cookbook - Second Edition
Ebook861 pages6 hours

MongoDB Cookbook - Second Edition

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Harness the latest features of MongoDB 3 with this collection of 80 recipes – from managing cloud platforms to app development, this book is a vital resource

About This Book

- Get to grips with the latest features of MongoDB 3
- Interact with the MongoDB server and perform a wide range of query operations from the shell
- From administration to automation, this cookbook keeps you up to date with the world’s leading NoSQL database

Who This Book Is For

This book is engineered for anyone who is interested in managing data in an easy and efficient way using MongoDB. You do not need any prior knowledge of MongoDB, but it would be helpful if you have some programming experience in either Java or Python.

What You Will Learn

- Install, configure, and administer MongoDB sharded clusters and replica sets
- Begin writing applications using MongoDB in Java and Python languages
- Initialize the server in three different modes with various configurations
- Perform cloud deployment and introduce PaaS for Mongo
- Discover frameworks and products built to improve developer productivity using Mongo
- Take an in-depth look at the Mongo programming driver APIs in Java and Python
- Set up enterprise class monitoring and backups of MongoDB

In Detail

MongoDB is a high-performance and feature-rich NoSQL database that forms the backbone of the systems that power many different organizations – it’s easy to see why it’s the most popular NoSQL database on the market. Packed with many features that have become essential for many different types of software professionals and incredibly easy to use, this cookbook contains many solutions to the everyday challenges of MongoDB, as well as guidance on effective techniques to extend your skills and capabilities.
This book starts with how to initialize the server in three different modes with various configurations. You will then be introduced to programming language drivers in both Java and Python. A new feature in MongoDB 3 is that you can connect to a single node using Python, set to make MongoDB even more popular with anyone working with Python. You will then learn a range of further topics including advanced query operations, monitoring and backup using MMS, as well as some very useful administration recipes including SCRAM-SHA-1 Authentication. Beyond that, you will also find recipes on cloud deployment, including guidance on how to work with Docker containers alongside MongoDB, integrating the database with Hadoop, and tips for improving developer productivity.
Created as both an accessible tutorial and an easy to use resource, on hand whenever you need to solve a problem, MongoDB Cookbook will help you handle everything from administration to automation with MongoDB more effectively than ever before.

Style and approach

Every recipe is explained in a very simple set-by-step manner yet is extremely comprehensive.
LanguageEnglish
Release dateJan 13, 2016
ISBN9781785286827
MongoDB Cookbook - Second Edition

Related to MongoDB Cookbook - Second Edition

Related ebooks

Enterprise Applications For You

View More

Related articles

Reviews for MongoDB Cookbook - Second Edition

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    MongoDB Cookbook - Second Edition - Dasadia Cyrus

    www.packtpub.com/authors.

    Customer support

    Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

    Downloading the example code

    You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

    Errata

    Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

    Piracy

    Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

    Please contact us at <copyright@packtpub.com> with a link to the suspected pirated material.

    We appreciate your help in protecting our authors, and our ability to bring you valuable content.

    Questions

    You can contact us at <questions@packtpub.com> if you are having a problem with any aspect of the book, and we will do our best to address it.

    Chapter 1. Installing and Starting the Server

    In this chapter, we will cover the following recipes:

    Installing single node MongoDB

    Starting a single node instance using the command-line options

    Installing single node MongoDB with options from the config file

    Connecting to a single node in the Mongo shell with JavaScript

    Connecting to a single node from a Java client

    Connecting to a single node from a Python client

    Starting multiple instances as part of a replica set

    Connecting to the replica set in the shell to query and insert data

    Connecting to the replica set to query and insert data from a Java client

    Connecting to the replica set to query and insert data using a Python client

    Starting a simple sharded environment of two shards

    Connecting to a shard in the shell and performing operations

    Introduction

    In this chapter, we will look at starting up the MongoDB server. Though it is a cakewalk to start the server with default settings for development purposes, there are numerous options available to fine-tune the start up behavior. We will start the server as a single node and then introduce various configuration options. We will conclude this chapter by setting up a simple replica set and running a sharded cluster. So, let's get started with installing and setting up the MongoDB server in the easiest way possible for simple development purposes.

    Installing single node MongoDB

    In this recipe, we will look at installing MongoDB in the standalone mode. This is the simplest and quickest way to start a MongoDB server, but it is seldom used for production use cases. However, this is the most common way to start the server for development purposes. In this recipe, we will start the server without looking at a lot of other startup options.

    Getting ready

    Well, assuming that we have downloaded the MongoDB binaries from the download site, extracted it, and have the resulting bin directory in the operating system's path variable. (This is not mandatory, but it really becomes convenient after doing so.) The binaries can be downloaded from http://www.mongodb.org/downloads after selecting your host operating system.

    How to do it…

    Create the directory, /data/mongo/db (or any of your choice). This will be our database directory, and it needs to have permission to write to it by the mongod (the mongo server process) process.

    We will start the server from the console with the data directory, /data/mongo/db, as follows:

    > mongod --dbpath  /data/mongo/db

    How it works…

    If you see the following line on the console, you have successfully started the server:

    [initandlisten] waiting for connections on port 27017

    Starting a server can't get easier than this. Despite the simplicity in starting the server, there are a lot of configuration options that can be used to tune the behavior of the server on startup. Most of the default options are sensible and need not be changed. With the default values, the server should be listening to port 27017 for new connections, and the logs will be printed out to the standard output.

    See also

    There are times where we would like to configure some options on server startup. In the Installing single node MongoDB recipe, we will use some more start up options.

    Starting a single node instance using command-line options

    In this recipe, we will see how to start a standalone single node server with some command-line options. We will see an example where we want to do the following:

    Start the server listening to port 27000

    Logs should be written to /logs/mongo.log

    The database directory is /data/mongo/db

    As the server has been started for development purposes, we don't want to preallocate full-size database files. (We will soon see what this means.)

    Getting ready

    If you have already seen and executed the Installing single node MongoDB recipe, you need not do anything different. If all these prerequisites are met, we are good for this recipe.

    How to do it…

    The /data/mongo/db directory for the database and /logs/ for the logs should be created and present on your filesystem with appropriate permissions to write to it.

    Execute the following command:

    > mongod --port 27000 --dbpath /data/mongo/db –logpath /logs/mongo.log --smallfiles

    How it works…

    Ok, this wasn't too difficult and is similar to the previous recipe, but we have some additional command-line options this time around. MongoDB actually supports quite a few options at startup, and we will see a list of the most common and important ones in my opinion:

    Enjoying the preview?
    Page 1 of 1