Teach Yourself NoSQL with MongoDB in 24 Hours (Learning Lab)


Author: Brad Dayley
Publisher: Sams Publishing
ISBN: 978-0-13-390299-0
Copyright © 2015 by Pearson Education, Inc.

Contents at a Glance


Part I: Getting Started with NoSQL and MongoDB

Hour 1: Introducing NoSQL and MongoDB

Hour 2: Installing and Configuring MongoDB

Hour 3: Using JavaScript in the MongoDB Shell

Part II: Implementing NoSQL in MongoDB

Hour 4: Configuring User Accounts and Access Control

Hour 5: Managing Databases and Collections from the MongoDB Shell

Hour 6: Finding Documents in the MongoDB Collection from the MongoDB Shell

Hour 7: Additional Data-Finding Operations Using the MongoDB Shell

Hour 8: Manipulating MongoDB Documents in a Collection

Hour 9: Utilizing the Power of Grouping, Aggregation, and Map Reduce

Part III: Using MongoDB in Applications

Hour 10: Implementing MongoDB in Java Applications

Hour 11: Accessing Data from MongoDB in Java Applications

Hour 12: Working with MongoDB Data in Java Applications

Hour 13: Implementing MongoDB in PHP Applications

Hour 14: Accessing Data from MongoDB in PHP Applications

Hour 15: Working with MongoDB Data in PHP Applications

Hour 16: Implementing MongoDB in Python Applications

Hour 17: Accessing Data from MongoDB in Python Applications

Hour 18: Working with MongoDB Data in Python Applications

Hour 19: Implementing MongoDB in Node.js Applications

Hour 20: Accessing Data from MongoDB in Node.js Applications

Hour 21: Working with MongoDB Data in Node.js Applications

Part IV: Additional MongoDB Concepts

Hour 22: Database Administration Using the MongoDB Shell

Hour 23: Implementing Replication and Sharding in MongoDB

Hour 24: Implementing a MongoDB GridFS Store


With billions of people using the Internet today, traditional RDBMS database solutions have difficulty meeting the rapidly growing need to handle large amounts of data. The growing trend is to introduce specialized databases that are not restricted to the conventions and the legacy overhead of traditional SQL databases. These databases are given the term NoSQL, meaning “Not Only SQL.” They are designed not to replace SQL databases, but to provide a different perspective in storing data.

This Learning Lab teaches you the concepts of NoSQL through the MongoDB perspective. MongoDB is a NoSQL database that has a reputation for being easy to implement while still robust and scalable. It is currently the most popular NoSQL database in use. MongoDB has matured into a stable platform that several companies have leveraged to provide the data scalability they require.

Each hour in the Learning Lab provides fundamentals for implementing and using MongoDB as back-end storage for high-performing applications. As you complete the 24 one-hour lessons in this tutorial, you will gain practical understanding of how to build, use, and maintain a MongoDB database.

So pull up a chair, sit back, and enjoy the process of learning NoSQL through the perspective of MongoDB development.

How This Learning Lab Is Organized

This Learning Lab is organized into four main parts:

Part I, “Getting Started with NoSQL and MongoDB,” covers the basic concepts of NoSQL, why you might want to use it, and available database types. It also covers MongoDB data structures and design concepts and explores what it takes to get MongoDB installed and running.

Part II, “Implementing NoSQL in MongoDB,” discusses the fundamental basics for implementing MongoDB. The hours in this part focus on creating databases and collections. They also cover the different methods of storing, finding, and retrieving data from the MongoDB database.

Part III, “Using MongoDB in Applications,” introduces you to the MongoDB drivers for some of the most common programming environments. A MongoDB driver is a library that provides the necessary tools to programmatically access and use the MongoDB database. This section covers the drivers for Java, PHP, Python, and Node.js. Each programming language section is isolated, so if you have no interest in a particular language, you can skip its corresponding hour.

Part IV, “Additional MongoDB Concepts,” rounds out your knowledge of MongoDB by teaching you additional MongoDB concepts. In this part, you learn some of the basics of administrating MongoDB databases and look at more advanced MongoDB concepts such as replication, sharding, and GridFS storage.


Tips and tricks to save you precious time are set aside in Tip boxes so that you can spot them quickly.


Note boxes highlight interesting information you want to be sure not to miss.


When you need to watch out for something, you’re warned about it in Caution boxes.

Code Examples

Two types of code examples appear in this tutorial. The most common are code snippets that appear in-line with the text to illustrate talking points. Try It Yourself sections also provide code examples. These examples are more robust and are designed to run as standalone mini applications. To keep the code examples small and easy to follow, they are compressed, with little or no error checking, for example.

The Try It Yourself examples are presented in listings that include line numbers to make them easier to follow. They also include a filename in the listing title to indicate which file the listing came from. If the code listing in the Try It Yourself section has specific output, a follow-up listing shows you the console output of the code so that you can follow along as you are reading.

Special Elements

As you complete each lesson, margin notes help you immediately apply what you just learned to your own web pages.

Whenever a new term is used, it is clearly highlighted—no flipping back and forth to a glossary.

Q&A, Quizzes, and Exercises

Every hour ends with a short question-and-answer session that addresses the kind of “dumb questions” all readers wish they dared to ask. A brief but complete quiz lets you test yourself to be sure you understand everything presented in the hour. Finally, one or two optional exercises give you a chance to practice your new skills before you move on.


For D!

A & F

About the Author

Brad Dayley is a senior software engineer with more than 20 years of experience developing enterprise applications. He has designed and developed large-scale business applications, including SAS applications with NoSQL database back ends and rich Internet web applications as front ends. He is the author of the jQuery and JavaScript Phrasebook, Sams Teach Yourself jQuery and JavaScript in 24 Hours, and Node.js, MongoDB and AngularJS Web Development.


I’d like to take this page to thank all those who made this title possible. First, I thank my wonderful wife and boys for giving me the inspiration and support I need. I’d never make it far without you. Thanks to Mark Taber for getting this title rolling in the right direction, Russell Kloepfer for his technical review, and Melissa Schirmer for managing everything on the production end.

We Want to Hear from You!

As the reader of this Learning Lab, you are our most important critic and commentator. We value your opinion and want to know what we’re doing right, what we could do better, what areas you’d like to see us publish in, and any other words of wisdom you’re willing to pass our way.

You can email or write to let us know what you did or didn’t like about this Learning Lab—as well as what we can do to make our Learning Labs stronger.

Please note that we cannot help you with technical problems related to the topic of this Learning Lab, and that due to the high volume of mail we receive, we might not be able to reply to every message.

When you write, please be sure to include this Learning Lab’s title, edition number, and author, as well as your name and contact information.


Mail:     Sams Publishing
              800 East 96th Street
              Indianapolis, IN 46240 USA

Reader Services

Visit our website and register this Learning Lab at for convenient access to any updates, downloads, or errata that might be available.