Book Image

MongoDB 4 Quick Start Guide

By : Doug Bierer
Book Image

MongoDB 4 Quick Start Guide

By: Doug Bierer

Overview of this book

MongoDB has grown to become the de facto NoSQL database with millions of users, from small start-ups to Fortune 500 companies. It can solve problems that are considered difficult, if not impossible, for aging RDBMS technologies. Written for version 4 of MongoDB, this book is the easiest way to get started with MongoDB. You will start by getting a MongoDB installation up and running in a safe and secure manner. You will learn how to perform mission-critical create, read, update, and delete operations, and set up database security. You will also learn about advanced features of MongoDB such as the aggregation pipeline, replication, and sharding. You will learn how to build a simple web application that uses MongoDB to respond to AJAX queries, and see how to make use of the MongoDB programming language driver for PHP. The examples incorporate new features available in MongoDB version 4 where appropriate.
Table of Contents (11 chapters)

Sharding

Command summary:

  • sh.addShard( "host:port" )
  • sh.enableSharding( "database" )
  • sh.shardCollection( "database.collection", { field: direction } )
  • sh.status()

Whereas replication is designed to provide redundancy of data, sharding is a feature which provides horizontal scaling. This means that instead of having a single extremely powerful server (vertical scaling), you spread the data across multiple servers operating in a cluster. This facility gives you the ability to handle massive amounts of data and lends itself to the cloud environment. Not only that, but because you have a subset of the entire database residing on multiple servers, each server is then able to handle its own database tasks, thus providing a means of load balancing.

Before we cover how to implement a sharded cluster, it's important to understand how sharding operates...