Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

MongoDB Comprehensive Guide

MongoDB Logo

Table of Contents

Introduction

MongoDB is a NoSQL database that provides high performance, high availability, and easy scalability. It is document-oriented, which means it stores data in JSON-like documents with dynamic schemas.

Installation

Prerequisites

macOS

brew tap mongodb/brew
brew install mongodb-community@5.0
brew services start mongodb/brew/mongodb-community

Windows

brew tap mongodb/brew
brew install mongodb-community@5.0
brew services start mongodb/brew/mongodb-community

Linux

Refer to the official MongoDB installation guide.

Basic Operations

CRUD Operations

Create

db.collection.insertOne({ name: "John", age: 30, city: "New York" });
db.collection.insertMany([{ name: "Jane", age: 25 }, { name: "Doe", age: 22 }]);

Read

db.collection.find({});
db.collection.find({ age: { $gt: 25 } });

Update

db.collection.updateOne({ name: "John" }, { $set: { age: 31 } });
db.collection.updateMany({ age: { $lt: 30 } }, { $set: { city: "San Francisco" } });

Delete

db.collection.deleteOne({ name: "John" });
db.collection.deleteMany({ age: { $lt: 25 } });

Indexes

db.collection.createIndex({ name: 1 });
db.collection.createIndex({ age: -1 });

Advanced Topics

Aggregation Framework

The aggregation framework provides an efficient way to perform data analysis operations.

db.collection.aggregate([
  { $match: { status: "A" } },
  { $group: { _id: "$cust_id", total: { $sum: "$amount" } } },
  { $sort: { total: -1 } }
]);

Replication

Replication provides redundancy and increases data availability. MongoDB achieves replication by applying operations on the primary to the secondary servers.

Sharding

Sharding is a method for distributing data across multiple machines. MongoDB uses sharding to support deployments with very large data sets and high throughput operations.

Best Practices

  • Use appropriate indexes to improve query performance.
  • Monitor your databases regularly.
  • Backup your data frequently.
  • Use replica sets for high availability.
  • Consider sharding for large datasets.

Resources

Contributing

Contributions are welcome!

About

MongoDB Comprehensive Guide

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors