Tsallaka zuwa abun ciki
Justice Tech School

MongoDB Tutorial

Store and query flexible documents with the MongoDB database.

Start learning MongoDB
Getting started6 lessons
  1. 1MongoDB IntroductionMongoDB is a document database.
  2. 2MongoDB Get StartedInstall MongoDB Community or create a free Atlas cluster in the cloud, then connect with m.
  3. 3Databases, Collections and DocumentsA database holds collections, a collection holds documents.
  4. 4BSON Data TypesDocuments are stored as BSON, which adds types to JSON: string, int, long, double, decimal.
  5. 5ObjectId and _idEvery document has a unique _id.
  6. 6Atlas, Compass and DriversMongoDB Atlas is the hosted cloud service.
Insert and read7 lessons
  1. 7Insert One DocumentinsertOne adds a single document and returns its _id.
  2. 8Insert Many DocumentsinsertMany adds an array of documents in one call.
  3. 9Find Documentsfind returns a cursor over matching documents.
  4. 10ProjectionThe second argument chooses which fields to return.
  5. 11Sort, Limit and Skipsort orders results, 1 ascending and -1 descending.
  6. 12Counting DocumentscountDocuments counts documents that match a filter.
  7. 13Cursors and Batchesfind returns a cursor that fetches documents in batches.
Query operators7 lessons
  1. 14Comparison Operators$eq, $ne, $gt, $gte, $lt, $lte, $in and $nin compare values.
  2. 15Logical Operators$and, $or, $nor and $not combine conditions.
  3. 16Element and Type Operators$exists tests whether a field is present and $type checks its BSON type.
  4. 17Text Matching with Regex$regex matches text patterns.
  5. 18Querying ArraysA filter on an array field matches if any element matches.
  6. 19Querying Nested DocumentsUse dot notation to reach into embedded documents and arrays by position.
  7. 20$expr and Computed Queries$expr lets a query compare two fields of the same document or use aggregation expressions.
Update and delete7 lessons
  1. 21Update DocumentsupdateOne and updateMany change documents with update operators such as $set.
  2. 22More Update Operators$inc adds to numbers, $unset removes fields, $rename renames, $min and $max keep the small.
  3. 23Updating Arrays$push adds an item, $addToSet adds if missing, $pull removes matches, $pop removes the fir.
  4. 24Upsert and ReplaceWith upsert: true, update inserts a document when nothing matches.
  5. 25findOneAndUpdatefindOneAndUpdate changes a document and returns it in one atomic step.
  6. 26Delete DocumentsdeleteOne removes the first match and deleteMany removes all matches.
  7. 27Bulk WritesbulkWrite sends many different operations in one round trip, which is much faster than sep.
Data modeling14 lessons
  1. 28Embedding versus ReferencingEmbed data that is read together and has a bounded size, such as an address.
  2. 29One to Many PatternsFew children: embed an array.
  3. 30Schema ValidationAdd a $jsonSchema validator to a collection so documents must match rules for types and re.
  4. 31IndexesAn index lets MongoDB find documents without scanning the collection.
  5. 32Explain Plansexplain shows how a query runs.
  6. 33Text and TTL IndexesA text index supports $text search.
  7. 34Embedding DocumentsStore related data inside one document.
  8. 35Referencing DocumentsStore the _id of another document.
  9. 36One to Many ModelingEmbed few, reference many.
  10. 37Schema Design RulesModel data how it is queried.
  11. 38Schema Validation$jsonSchema enforces shape.
  12. 39Capped CollectionsFixed size collections that overwrite oldest data.
  13. 40TTL IndexesExpire documents automatically.
  14. 41Working with DatesUse Date objects for time queries.
Aggregation7 lessons
  1. 42Aggregation Pipelineaggregate runs documents through stages such as $match, $group, $sort and $project.
  2. 43$match, $project and $addFields$match filters early, $project chooses or renames fields and $addFields adds computed fiel.
  3. 44$group AccumulatorsAccumulators include $sum, $avg, $min, $max, $first, $last, $push and $addToSet.
  4. 45$unwind$unwind turns an array into one document per element so you can group or count items.
  5. 46$lookup: Joins$lookup joins another collection like a left outer join.
  6. 47$facet, $bucket and $count$bucket groups by ranges, $facet runs several pipelines on the same input at once and $cou.
  7. 48$out and $merge$out writes pipeline results to a new collection and $merge updates or inserts into an exi.
Advanced MongoDBPremium8 lessons
  1. 49TransactionsMulti document transactions give ACID guarantees across documents and collections on repli.
  2. 50Replica SetsA replica set copies data across servers for availability.
  3. 51ShardingSharding spreads data across machines by a shard key.
  4. 52Read and Write ConcernWrite concern sets how many servers must confirm a write, such as w: "majority".
  5. 53Change StreamsChange streams let your app subscribe to inserts, updates and deletes in real time on repl.
  6. 54Atlas Search and Vector SearchAtlas offers full text search and vector search inside MongoDB with the $search and $vecto.
  7. 55Time Series CollectionsTime series collections store measurements efficiently with a time field and optional meta.
  8. 56GridFS and Large FilesDocuments are limited to 16 MB.
MongoDB in practicePremium10 lessons
  1. 57Security ChecklistTurn on authentication, create users with least privilege roles, use TLS, restrict network.
  2. 58Backup and Restoremongodump exports data and mongorestore imports it.
  3. 59Import and Export Datamongoimport loads JSON or CSV files and mongoexport writes them.
  4. 60MongoDB with Node.js and MongooseMongoose adds schemas, validation and models on top of the Node driver.
  5. 61MongoDB with PythonPyMongo is the official Python driver.
  6. 62Monitoring and PerformanceWatch slow queries with the profiler, check index use with explain, monitor memory, connec.
  7. 63Schema Design PatternsCommon patterns: bucket for time data, computed for stored totals, subset for hot fields, .
  8. 64Migrating from SQLMap tables to collections, rows to documents and joins to embedding or $lookup.
  9. 65MongoDB Best PracticesDesign for your queries, index what you filter and sort, avoid unbounded arrays, use proje.
  10. 66Next StepsYou can now model data, query, update and aggregate with MongoDB.
MongoDB basics16 lessons
  1. 67What is MongoDBA document database that stores JSON like documents in collections.
  2. 68Databases, Collections, DocumentsA database holds collections and a collection holds documents.
  3. 69Using mongoshmongosh is the interactive shell.
  4. 70BSON TypesMongoDB stores BSON with types like String, Int32, Double, Date and ObjectId.
  5. 71ObjectId_id defaults to a 12 byte ObjectId.
  6. 72insertOneAdd one document.
  7. 73insertManyAdd several documents in one call.
  8. 74findRead documents.
  9. 75ProjectionChoose fields to return.
  10. 76Comparison Operators$eq, $ne, $gt, $gte, $lt, $lte, $in and $nin.
  11. 77Logical Operators$and, $or, $nor and $not combine conditions.
  12. 78$exists and $typeCheck field presence and type.
  13. 79Regular ExpressionsMatch text with $regex.
  14. 80sort, limit and skipOrder and page results.
  15. 81CountingcountDocuments counts matches.
  16. 82distinctList unique values of a field.
Updating and deleting11 lessons
  1. 83updateOne and $setChange fields in one document.
  2. 84updateManyChange many documents.
  3. 85$inc and $mulChange numbers in place.
  4. 86$unset and $renameRemove or rename fields.
  5. 87Array Updates$push adds, $pull removes and $addToSet adds without duplicates.
  6. 88Positional UpdateThe $ operator updates the matched array item.
  7. 89UpsertInsert when nothing matches.
  8. 90replaceOneReplace the whole document.
  9. 91findOneAndUpdateUpdate and return the document.
  10. 92Deleting DocumentsdeleteOne and deleteMany remove documents.
  11. 93Dropping Collectionsdrop removes a collection and its documents.
Indexes and aggregation12 lessons
  1. 94Creating IndexesIndexes speed up queries.
  2. 95Unique IndexesPrevent duplicate values.
  3. 96Compound IndexesIndex several fields in order.
  4. 97explainSee how a query runs.
  5. 98Text SearchText indexes support $text.
  6. 99Aggregation PipelineStages transform documents in order.
  7. 100$groupGroup and total values.
  8. 101$project and $addFieldsReshape documents.
  9. 102$lookupA left outer join.
  10. 103$unwindFlatten arrays into documents.
  11. 104$sort, $limit, $skipOrder and slice in a pipeline.
  12. 105$count and $facetCount and run sub pipelines.
MongoDB in applications16 lessons
  1. 106Using the Node DriverConnect and query from Node.js.
  2. 107Mongoose BasicsMongoose adds schemas and models.
  3. 108Connection StringsURIs describe how to connect.
  4. 109MongoDB AtlasAtlas is hosted MongoDB.
  5. 110Users and RolesCreate users with limited roles.
  6. 111Backup and Restoremongodump and mongorestore copy data.
  7. 112Import and Exportmongoimport and mongoexport move JSON or CSV.
  8. 113Transactions IntroMulti document transactions need a replica set.
  9. 114Replica SetsCopies of data across servers for availability.
  10. 115Sharding IntroSplit data across servers by a shard key.
  11. 116Project: Contacts BookPractice all CRUD operations.
  12. 117Project: Blog DataPosts with embedded comments.
  13. 118Project: Sales ReportGroup orders by customer.
  14. 119Security BasicsEnable auth, restrict network access and never expose the port.
  15. 120Performance TipsIndex filters and sorts, project only needed fields, avoid huge documents.
  16. 121MongoDB Best PracticesDesign for queries, add indexes, validate schemas and monitor.