MongoDB Fundamentals: A hands-on guide to using MongoDB and Atlas in the real world
Book information
Description
Learn how to deploy and monitor databases in the cloud, manipulate documents, visualize data, and build applications running on MongoDB using Node.js Key FeaturesLearn the fundamentals of NoSQL databases with MongoDBCreate, manage, and optimize a MongoDB database in the cloud using AtlasUse a real-world dataset to gain practical experience of handling big dataBook Description MongoDB is one of the most popular database technologies for handling large collections of data. This book will help MongoDB beginners develop the knowledge and skills to create databases and process data efficiently. Unlike other MongoDB books, MongoDB Fundamentals dives into cloud computing from the very start – showing you how to get started with Atlas in the first chapter. You will discover how to modify existing data, add new data into a database, and handle complex queries by creating aggregation pipelines. As you progress, you'll learn about the MongoDB replication architecture and configure a simple cluster. You will also get to grips with user authentication, as well as techniques for backing up and restoring data. Finally, you'll perform data visualization using MongoDB Charts. You will work on realistic projects that are presented as bitesize exercises and activities, allowing you to challenge yourself in an enjoyable and attainable way. Many of these mini-projects are based around a movie database case study, while the last chapter acts as a final project where you will use MongoDB to solve a real-world problem based on a bike-sharing app. By the end of this book, you'll have the skills and confidence to process large volumes of data and tackle your own projects using MongoDB. What you will learnSet up and use MongoDB Atlas on the cloudInsert, update, delete, and retrieve data from MongoDBBuild aggregation pipelines to perform complex queriesOptimize queries using indexesMonitor databases and manage user authorizationImprove scalability and performance with sharding clustersReplicate clusters, back up your database, and restore dataCreate data-driven charts and reports from real-time dataWho this book is for This book is designed for people who are new to MongoDB. It is suitable for developers, database administrators, system administrators, and cloud architects who are looking to use MongoDB for smooth data processing in the cloud. Although not necessary, basic knowledge of a general programming language and experience with other databases will help you grasp the topics covered more easily. Table of ContentsIntroduction to MongoDBDocuments and Data TypesServers and ClientsQuerying DocumentsInserting, Updating, and Deleting DocumentsUpdating with Aggregation Pipelines and ArraysData AggregationCoding JavaScript in MongoDBPerformanceReplicationBackup and Restore in MongoDBData VisualizationMongoDB Case Study Cover FM Copyright Table of Contents Preface Chapter 1: Introduction to MongoDB Introduction Database Management Systems Relational Database Management Systems NoSQL Database Management Systems Comparison Introduction to MongoDB MongoDB Editions Migrating Community Edition to Enterprise Edition The MongoDB Deployment Model Managing MongoDB Self-Managed Managed Service: Database as a Service MongoDB Atlas MongoDB Atlas Benefits Cloud Providers Availability Zones Regions MongoDB Supported Regions and Availability Zones Atlas Tiers MongoDB Atlas Pricing Cluster Cost Estimation Exercise 1.01: Setting Up a MongoDB Atlas Account MongoDB Atlas Organizations, Projects, Users, and Clusters Organizations Exercise 1.02: Setting Up a MongoDB Atlas Organization Projects Exercise 1.03: Creating a MongoDB Atlas Project MongoDB Clusters Exercise 1.04: Setting Up Your First Free MongoDB Cluster on Atlas Connecting to Your MongoDB Atlas Cluster MongoDB Elements Documents Document Structures Collections Understanding MongoDB Databases Creating a Database Creating a Collection Creating a Collection Using Document Insertion Creating Documents Inserting a Single Document Inserting Multiple Documents Fetching Documents from MongoDB Formatting the find Output Using the pretty() Method Activity 1.01: Setting Up a Movies Database Summary Chapter 2: Documents and Data Types Introduction Introduction to JSON JSON Syntax JSON Data Types JSON and Numbers JSON and Dates Exercise 2.01: Creating Your Own JSON Document BSON MongoDB Documents Documents and Flexibility MongoDB Data Types Strings Numbers Booleans Objects Exercise 2.02: Creating Nested Objects Arrays Exercise 2.03: Using Array Fields Null ObjectId Dates Timestamps Binary Data Limits and Restrictions on Documents Document Size Limit Nesting Depth Limit Field Name Rules Exercise 2.04: Loading Data into an Atlas Cluster Activity 2.01: Modeling a Tweet into a JSON Document Summary Chapter 3: Servers and Clients Introduction Network Access Network Protocols Public versus Private IP Addresses Domain Name Server Transmission Control Protocol The Wire Protocol Network Access Configuration The IP Access List Temporary Access Network Peering Exercise 3.01: Enabling Network Access Database Access User Authentication Username Storage Username Authentication Configuring Authentication in Atlas Temporary Users Database Privileges and Roles Predefined Roles Configuring Built-In Roles in Atlas Advanced Privileges Exercise 3.02: Configuring Database Access Configuring Custom Roles The Database Client Connection Strings The Mongo Shell Exercise 3.03: Connecting to the Cloud Database Using the Mongo Shell MongoDB Compass MongoDB Drivers Exercise 3.04: Connecting to a MongoDB Cloud Database Using the Python Driver Server Commands Physical Structure Database Files Database Metrics Logical Structure Server Commands Exercise 3.05: Creating a Database View Object Activity 3.01: Managing Your Database Users Summary Chapter 4: Querying Documents Introduction MongoDB Query Structure Basic MongoDB Queries Finding Documents Using findOne() Exercise 4.01: Using find() and findOne() Without a Condition Choosing the Fields for the Output Finding the Distinct Fields Counting the Documents count() countDocuments() estimatedDocumentCount() Conditional Operators Equals ($eq) Not Equal To ($ne) Greater Than ($gt) and Greater Than or Equal To ($gte) Less Than ($lt) and Less Than or Equal To ($lte) In ($in) and Not In ($nin) Exercise 4.02: Querying for Movies of an Actor Logical Operators $and operator $or Operator $nor Operator $not Operator Exercise 4.03: Combining Multiple Queries Regular Expressions Using the caret (^) operator Using the dollar ($) operator Case-Insensitive Search Query Arrays and Nested Documents Finding an Array by an Element Finding an Array by an Array Searching an Array with the $all Operator Projecting Array Elements Projecting Matching Elements Using ($) Projecting Matching Elements by their Index Position ($slice) Querying Nested Objects Querying Nested Object Fields Exercise 4.04: Projecting Nested Object Fields Limiting, Skipping, and Sorting Documents Limiting the Result Limit and Batch Size Positive Limit with Batch Size Negative Limits and Batch Size Skipping Documents Sorting Documents Activity 4.01: Finding Movies by Genre and Paginating Results Summary Chapter 5: Inserting, Updating, and Deleting Documents Introduction Inserting Documents Inserting Multiple Documents Inserting Duplicate Keys Inserting without _id Deleting Documents Deleting Using deleteOne() Exercise 5.01: Deleting One of Many Matched Documents Deleting Multiple Documents Using deleteMany() Deleting Using findOneAndDelete() Exercise 5.02: Deleting a Low-Rated Movie Replacing Documents _id Fields Are Immutable Upsert Using Replace Why Use Upsert? Replacing Using findOneAndReplace() Replace versus Delete and Re-Insert Modify Fields Updating a Document with updateOne() Modifying More Than One Field Multiple Documents Matching a Condition Upsert with updateOne() Updating a Document with findOneAndUpdate() Returning a New Document in Response Sorting to Find a Document Exercise 5.03: Updating the IMDb and Tomatometer Rating Updating Multiple Documents with updateMany() Update Operators Set ($set) Increment ($inc) Multiply ($mul) Rename ($rename) Current Date ($currentDate) Removing Fields ($unset) Setting When Inserted ($setOnInsert) Activity 5.01: Updating Comments for Movies Summary Chapter 6: Updating with Aggregation Pipelines and Arrays Introduction Updating with an Aggregation Pipeline (MongoDB 4.2) Stage 1 ($set) Stage 2 ($set) Stage 3 ($project) Updating Array Fields Exercise 6.01: Adding Elements to Arrays Adding Multiple Elements Sort Array An Array as a Set Exercise 6.02: New Category of Classic Movies Removing Array Elements Removing the First or Last Element ($pop) Removing All Elements Removing Matched Elements Updating Array Elements Exercise 6.03: Updating the Director's Name Activity 6.01: Adding an Actor's Name to the Cast Summary Chapter 7: Data Aggregation Introduction aggregate Is the New find Aggregate Syntax The Aggregation Pipeline Pipeline Syntax Creating Aggregations Exercise 7.01: Performing Simple Aggregations Exercise 7.02: Aggregation Structure Manipulating Data The Group Stage Accumulator Expressions Exercise 7.03: Manipulating Data Exercise 7.04: Selecting the Title from Each Movie Category Working with Large Datasets Sampling with $sample Joining Collections with $lookup Outputting Your Results with $out and $merge Exercise 7.05: Listing the Most User-Commented Movies Getting the Most from Your Aggregations Tuning Your Pipelines Filter Early and Filter Often Use Your Indexes Think about the Desired Output Aggregation Options Exercise 7.06: Finding Award-Winning Documentary Movies Activity 7.01: Putting Aggregations into Practice Summary Chapter 8: Coding JavaScript in MongoDB Introduction Connecting to the Driver Introduction to Node.js Getting the MongoDB Driver for Node.js The Database and Collection Objects Connection Parameters Exercise 8.01: Creating a Connection with the Node.js Driver Executing Simple Queries Creating and Executing find Queries Using Cursors and Query Results Exercise 8.02: Building a Node.js Driver Query Callbacks and Error Handling in Node.js Callbacks in Node.js Basic Error Handling in Node.js Exercise 8.03: Error Handling and Callbacks with the Node.js Driver Advanced Queries Inserting Data with the Node.js Driver Updating and Deleting Data with the Node.js Driver Writing Reusable Functions Exercise 8.04: Updating Data with the Node.js Driver Reading Input from the Command Line Creating an Interactive Loop Exercise 8.05: Handling Inputs in Node.js Activity 8.01: Creating a Simple Node.js Application Summary Chapter 9: Performance Introduction Query Analysis Explaining the Query Viewing Execution Stats Identifying Problems Linear Search Introduction to Indexes Creating and Listing Indexes Listing Indexes on a Collection Index Names Exercise 9.01: Creating an Index Using MongoDB Atlas Query Analysis after Indexes Hiding and Dropping Indexes Dropping Multiple Indexes Hiding an Index Exercise 9.02: Dropping an Index Using Mongo Atlas Type of Indexes Default Indexes Single-Key Indexes Compound Indexes Multikey Indexes Text Indexes Indexes on Nested Documents Wildcard Indexes Properties of Indexes Unique Indexes Exercise 9.03: Creating a Unique Index TTL Indexes Exercise 9.04: Creating a TTL index using Mongo Shell Sparse Indexes Exercise 9.05: Creating a Sparse Index Using Mongo Shell Partial Indexes Exercise 9.06: Creating a Partial Index Using the Mongo Shell Case-Insensitive Indexes Exercise 9.07: Creating a Case-Insensitive Index Using the Mongo Shell Other Query Optimization Techniques Fetch Only What You Need Sorting Using Indexes Fitting Indexes in the RAM Index Selectivity Providing Hints Optimal Indexes Activity 9.01: Optimizing a Query Summary Chapter 10: Replication Introduction High-Availability Clusters Cluster Nodes Share-Nothing Cluster Names Replica Sets Primary-Secondary The Oplog Replication Architecture Cluster Members The Election Process Exercise 10.01: Checking Atlas Cluster Members Client Connections Connecting to a Replica Set Single-Server Connections Exercise 10.02: Checking the Cluster Replication Read Preference Write Concern Deploying Clusters Atlas Deployment Manual Deployment Exercise 10.03: Building Your Own MongoDB Cluster Enterprise Deployment Cluster Operations Adding and Removing Members Adding a Member Removing a Member Reconfiguring a Cluster Failover Failover (Outage) Rollback Switchover (Stepdown) Exercise 10.04: Performing Database Maintenance Activity 10.01: Testing a Disaster Recovery Procedure for a MongoDB Database Summary Chapter 11: Backup and Restore in MongoDB Introduction The MongoDB Utilities Exporting MongoDB Data Using mongoexport mongoexport Options Exercise 11.01: Exporting MongoDB Data Importing Data into MongoDB Using mongoimport mongoimport Options Exercise 11.02: Loading Data into MongoDB Backing up an Entire Database Using mongodump mongodump Options Exercise 11.03: Backing up MongoDB Restoring a MongoDB Database Using mongorestore The mongorestore Options Exercise 11.04: Restoring MongoDB Data Activity 11.01: Backup and Restore in MongoDB Summary Chapter 12: Data Visualization Introduction Exploring Menus and Tabs Dashboards Data Sources Exercise 12.01: Working with Data Sources Data Source Permissions Building Charts Fields Types of Charts Bar and Column Charts Exercise 12.02: Creating a Bar Chart to Display Movies Circular Charts Exercise 12.03: Creating a Pie Chart Graph from the Movies Collection Geospatial Charts Exercise 12.04: Creating a Geospatial Chart Complex Charts Preprocessing and Filtering Data Filtering Data Adding Custom Fields Changing Fields Channels Aggregation and Binning Exercise 12.05: Binning Values for a Bar Graph Integration Embedded Charts Exercise 12.06: Adding Charts to HTML pages Activity 12.01: Creating a Sales Presentation Dashboard Summary Chapter 13: MongoDB Case Study Introduction Fair Bay City Council Fair Bay City Bikes Proposal Highlights Dockless Bikes Ease of Use Real-Time Tracking Maintenance and Care Technical Discussions and Decisions Quick Rollout Cost Effective Flexible Database Design Users Vehicles Rides Ride Logs Use Cases User Finds Available Bikes User Unlocks a Bike User Locks the Bike System Logs the Geographical Coordinates of Rides System Sends Bikes for Maintenance Technician Performs Fortnightly Maintenance Generating Stats Summary Appendix Index
Similar books
MongoDB Fundamentals
2020 · MOBI
MongoDB Fundamentals
2020 · EPUB
High Wood (Battleground)
2017 · EPUB
The Oxford Treasury of Classic Poems
1996 · PDF
Mathematics for Economics and Finance
2011 · PDF
Fire From Heaven
1977 · PDF
Mathematical Economics and Finance
1998 · PDF
The Roots of Witchcraft
1975 · PDF