🍃 MongoDB Tutorials

Choose a lesson below to start learning MongoDB.

  1. 1.MongoDB Tutorial: Introduction to MongoDB (NoSQL Database)Learn what MongoDB is, how it stores data as documents, and how it compares to a traditional RDBMS like MySQL — with a real BSON example.
  2. 2.MongoDB Databases: Show, Create, Rename & Drop DatabaseLearn every MongoDB database command — show dbs, use to create or switch databases, how to rename a database, and dropDatabase() to delete one.
  3. 3.MongoDB Collections: Show, Create, Rename & Drop CollectionLearn how to list, create, rename, and delete collections in MongoDB, including createCollection() and the two ways collections get created automatically.
  4. 4.MongoDB Data Types Explained (String, Int, Array, ObjectId & More)A complete list of MongoDB's supported BSON data types — String, Integer, Boolean, Array, Date, ObjectId, Binary data, and more — with what each is used for.
  5. 5.Insert Documents in MongoDB: insertOne, insertMany, Arrays & ObjectsLearn how to insert one document, many documents, arrays, and embedded objects in MongoDB, plus how to enforce uniqueness with createIndex().
  6. 6.MongoDB find() and findOne() Tutorial: Query & ProjectionLearn MongoDB's find() and findOne() methods, how to filter documents with a query object, query nested fields, and select specific fields with projection.
  7. 7.MongoDB Comparison Operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $ninA complete guide to MongoDB's comparison query operators with real examples for $eq, $ne, $gt, $gte, $lt, $lte, $in and $nin.
  8. 8.MongoDB Logical Operators: $and, $or, $nor, $not (With Examples)Learn how to combine multiple MongoDB query conditions using $and, $or, $nor and $not — with practical examples and common pitfalls.
  9. 9.MongoDB Element Operators: $exists and $type ExplainedLearn how to query MongoDB documents by field existence with $exists and by field data type with $type, including all BSON type aliases.
  10. 10.MongoDB Evaluation Operators: $expr, $mod, $regex, $text, $whereLearn MongoDB's evaluation query operators — comparing two fields with $expr, modulo matching with $mod, pattern matching with $regex, full-text search with $text, and $where.
  11. 11.MongoDB Array Query Operators: $all, $size, $elemMatchLearn how to query MongoDB array fields with $all (contains all values), $size (exact array length), and $elemMatch (matching multiple conditions on one element).
  12. 12.MongoDB $comment Operator: Tagging Queries for DebuggingLearn how MongoDB's $comment operator lets you attach a note to a query so it's easy to identify later in logs and the profiler.
  13. 13.Update Documents in MongoDB: updateOne, updateMany & upsertLearn how to update MongoDB documents with updateOne() and updateMany(), update nested/embedded fields, and use upsert to insert-or-update in one call.
  14. 14.MongoDB Field Update Operators: $set, $inc, $unset, $rename & MoreA complete reference for MongoDB's field update operators — $set, $inc, $min, $max, $mul, $rename, $unset, $setOnInsert and $currentDate — with real examples.
  15. 15.MongoDB Array Update Operators: $push, $pull, $addToSet, $pop & Positional $Learn every MongoDB array update operator — $push, $pull, $pullAll, $addToSet, $pop, the positional $, $[], $[identifier], and modifiers like $each, $position, $slice, $sort.
  16. 16.Delete Documents in MongoDB: deleteOne, deleteMany & remove()Learn how to delete documents in MongoDB with deleteOne() and deleteMany(), and the difference from the legacy remove() method.
  17. 17.MongoDB sort(), skip() and limit() Explained (With Pagination Example)Learn how to order query results with sort(), skip a number of documents with skip(), and cap results with limit() — the building blocks of MongoDB pagination.
  18. 18.MongoDB Counting Documents: countDocuments() vs count() vs itcount()Learn the right way to count documents in MongoDB using countDocuments(), why the older count() is deprecated, and when to use cursor.itcount() instead.
  19. 19.MongoDB distinct() Method: Get Unique Field ValuesLearn how to use MongoDB's distinct() method to get every unique value for a field across a collection, filter it, and count the results with .length.
  20. 20.MongoDB findAndModify, findOneAndUpdate, findOneAndDelete & findOneAndReplaceLearn MongoDB's atomic find-and-modify style methods — findAndModify(), findOneAndUpdate(), findOneAndDelete(), and findOneAndReplace() — with returnNewDocument examples.
  21. 21.MongoDB Utility Methods: Find by ObjectId, validate() & Storage SizeLearn how to query MongoDB by _id/ObjectId, validate a collection for corruption, and check a collection's storage size with storageSize() and totalSize().
  22. 22.MongoDB Indexing Basics: Why Indexes Matter and createIndex()Learn what indexing is in MongoDB, why it dramatically speeds up queries, and how to create your first index with createIndex() — with an explain() comparison.
  23. 23.MongoDB Unique Indexes: Enforcing No Duplicate ValuesLearn how to create a unique index in MongoDB to prevent duplicate values like emails, how it applies to embedded fields, and how createIndexes() creates several at once.
  24. 24.Types of MongoDB Indexes: Single Field, Compound, Multikey, Text & MoreA complete guide to every MongoDB index type — single field, compound, multikey (array), geospatial, text, and wildcard indexes — with syntax and examples for each.
  25. 25.Manage MongoDB Indexes: getIndexes(), dropIndex() & dropIndexes()Learn how to list every index on a MongoDB collection with getIndexes(), remove a single index with dropIndex(), and remove several at once with dropIndexes().
  26. 26.MongoDB Aggregation Pipeline Explained (Stages, Expressions & Accumulators)Learn what the MongoDB aggregation pipeline is, how documents flow through stages like $match and $group, and the difference between stages, expressions and accumulators.
  27. 27.MongoDB Aggregation: $match and $project Stages ExplainedLearn how the $match aggregation stage filters documents like find(), and how $project selects and reshapes the fields returned from an aggregation pipeline.
  28. 28.MongoDB $group Stage: Grouping Documents in AggregationLearn how MongoDB's $group aggregation stage groups documents by a field value, and how to combine it with $match to group only a filtered subset.
  29. 29.MongoDB $group Accumulators: $sum, $avg, $min, $max, $push & $addToSetLearn every MongoDB $group accumulator operator — $sum, $count, $avg, $min, $max, $first, $last, $push and $addToSet — with real aggregation examples.
  30. 30.MongoDB Aggregation: $sort, $skip, $limit, $unwind and $out StagesLearn the remaining MongoDB aggregation pipeline stages — $sort, $skip, $limit for ordering and paging results, $unwind for arrays, and $out to save results to a new collection.
  31. 31.MongoDB String Expression Operators: $toUpper, $toLower, $concatLearn how to transform text inside a MongoDB aggregation pipeline with $toUpper, $toLower and $concat — including how to build a new string field from multiple values.
  32. 32.MongoDB Backup & Restore: mongodump and mongorestore ExplainedLearn how to back up and restore MongoDB data at every level — the whole server, a single database, or just one collection — using mongodump and mongorestore.
  33. 33.Export & Import a MongoDB Collection Using MongoDB CompassLearn how to export a MongoDB collection to a file and import data into a new collection using the MongoDB Compass GUI — no command line required.
  34. 34.MongoDB mongoexport & mongoimport: JSON and CSV from the Command LineLearn how to export a MongoDB collection to JSON or CSV with mongoexport, including limiting rows and picking specific fields, then load it back in with mongoimport.