Book Image

MongoDB Administrator???s Guide

By : Cyrus Dasadia
Book Image

MongoDB Administrator???s Guide

By: Cyrus Dasadia

Overview of this book

MongoDB is a high-performance and feature-rich NoSQL database that forms the backbone of the systems that power many different organizations. Packed with many features that have become essential for many different types of software professional and incredibly easy to use, this cookbook contains more than 100 recipes to address the everyday challenges of working with MongoDB. Starting with database configuration, you will understand the indexing aspects of MongoDB. The book also includes practical recipes on how you can optimize your database query performance, perform diagnostics, and query debugging. You will also learn how to implement the core administration tasks required for high-availability and scalability, achieved through replica sets and sharding, respectively. You will also implement server security concepts such as authentication, user management, role-based access models, and TLS configuration. You will also learn how to back up and recover your database efficiently and monitor server performance. By the end of this book, you will have all the information you need—along with tips, tricks, and best practices—to implement a high-performance MongoDB solution.
Table of Contents (17 chapters)
Title Page
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Installing and starting MongoDB on macOS


Similar to the previous recipe, Installing and starting MongoDB on Linux, we will see how to set up MongoDB on a macOS operating system.

Getting ready

MongoDB supports macOS 10.7 (Lion) or higher, so ensure that your operating system is upgraded. Download the binary files the latest stable binary tarball from https://www.mongodb.com/download-center.

How to do it...

  1. In this recipe, we will be installing MongoDB in the user's home directory. Create a directory ~/data/ and extract the TAR file in this directory:
tar xvf mongodb-osx-x86_64-3.4.4.tgz

All of MongoDB's core binaries are available in the ~/data/mongodb-osx-x86_64-3.4.4/bin directory.

  1. Create a symbolic link to the versioned file directory for simpler naming conventions and also allowing us to use a generic directory name (for example, in scripts):
cd ~/data/
ln -s mongodb-osx-x86_64-3.4.4 mongodb
  1. Create a directory for the database:
mkdir ~/data/db
  1. Start the MongoDB server:
~/data/mongodb/bin/mongod --dbpath ~/data/db
  1. You should see output like this:
2017-05-21T15:21:20.662+0530 I CONTROL  [initandlisten] MongoDB starting : pid=960 port=27017 dbpath=/Users/cyrus.dasadia/data/db 64-bit host=foo
 2017-05-21T15:21:20.662+0530 I CONTROL  [initandlisten] db version v3.4.4
 2017-05-21T15:21:20.662+0530 I CONTROL  [initandlisten] git version: 888390515874a9debd1b6c5d36559ca86b44babd
 2017-05-21T15:21:20.662+0530 I CONTROL  [initandlisten] allocator: system
 2017-05-21T15:21:20.662+0530 I CONTROL  [initandlisten] modules: none
 2017-05-21T15:21:20.662+0530 I CONTROL  [initandlisten] build environment:
 2017-05-21T15:21:20.662+0530 I CONTROL  [initandlisten]     distarch: x86_64
 2017-05-21T15:21:20.662+0530 I CONTROL  [initandlisten]     target_arch: x86_64
 2017-05-21T15:21:20.662+0530 I CONTROL  [initandlisten] options: { storage: { dbPath: "/Users/cyrus.dasadia/data/db" } }
 <<--- snip -- >>
 2017-05-21T15:21:21.492+0530 I NETWORK  [thread1] waiting for connections on port 27017
  1. You can press Ctrl + C to stop the server.

 

  1. Additionally, for convenience, we can edit the system's PATH variable to include the MongoDB binaries directory. This allows us invoke the MongoDB binaries without having to type the entire path. For example, to execute the mongo client, instead of having to type ~/mongodb/bin/mongo every time we can simply type mongo. This can be done by appending your ~/.bashrc or ~/.zshrc files for bash and zsh respectively, with the following lines:
PATH=~/data/mongodb/bin:${PATH}
export PATH

How it works…

Similar to our first recipe, we downloaded a precompiled binary package and started the MongoDB server using the most basic command line parameter --dbpath such that it uses a customized directory ~/data/db for storing databases. As you might have noticed, MongoDB server by default, starts listening on TCP 27017 on all interfaces. We also saw how to add the MongoDB binary directory's path to our system's PATH variable for a more convenient way to access the MongoDB binaries.