Book Image

Mastering MongoDB 4.x - Second Edition

By : Alex Giamas
Book Image

Mastering MongoDB 4.x - Second Edition

By: Alex Giamas

Overview of this book

MongoDB is the best platform for working with non-relational data and is considered to be the smartest tool for organizing data in line with business needs. The recently released MongoDB 4.x supports ACID transactions and makes the technology an asset for enterprises across the IT and fintech sectors. This book provides expertise in advanced and niche areas of managing databases (such as modeling and querying databases) along with various administration techniques in MongoDB, thereby helping you become a successful MongoDB expert. The book helps you understand how the newly added capabilities function with the help of some interesting examples and large datasets. You will dive deeper into niche areas such as high-performance configurations, optimizing SQL statements, configuring large-scale sharded clusters, and many more. You will also master best practices in overcoming database failover, and master recovery and backup procedures for database security. By the end of the book, you will have gained a practical understanding of administering database applications both on premises and on the cloud; you will also be able to scale database applications across all servers.
Table of Contents (20 chapters)
Free Chapter
1
Section 1: Basic MongoDB – Design Goals and Architecture
4
Section 2: Querying Effectively
10
Section 3: Administration and Data Management
15
Section 4: Scaling and High Availability

CRUD using the shell

The mongo shell is equivalent to the administration console used by relational databases. Connecting to the mongo shell is as easy as typing the following code:

$ mongo

Type this on the command line for standalone servers or replica sets. Inside the shell, you can view available databases simply by typing the following code:

$ db

Then, you can connect to a database by typing the following code:

> use <database_name>

The mongo shell can be used to query and update data into our databases. Inserting this document in the books collection can be done as follows:

> db.books.insert({title: 'mastering mongoDB', isbn: '101'})
WriteResult({ "nInserted" : 1 })

We can then find documents from a collection named books by typing the following:

> db.books.find()
{ "_id" : ObjectId("592033f6141daf984112d07c"...