{"id":20862851,"url":"https://github.com/quickheaven/complete-mongo-db-tutorial","last_synced_at":"2026-04-12T06:32:09.201Z","repository":{"id":103705473,"uuid":"597603946","full_name":"quickheaven/complete-mongo-db-tutorial","owner":"quickheaven","description":"The Complete MongoDB Tutorial","archived":false,"fork":false,"pushed_at":"2023-02-10T03:27:49.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-19T07:45:11.879Z","etag":null,"topics":["express-js","expressjs","mongodb","mongodb-database","node-js","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quickheaven.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-05T03:19:35.000Z","updated_at":"2023-02-05T17:52:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"f062312d-a4ba-4763-b83b-8160dead1c93","html_url":"https://github.com/quickheaven/complete-mongo-db-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quickheaven%2Fcomplete-mongo-db-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quickheaven%2Fcomplete-mongo-db-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quickheaven%2Fcomplete-mongo-db-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quickheaven%2Fcomplete-mongo-db-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quickheaven","download_url":"https://codeload.github.com/quickheaven/complete-mongo-db-tutorial/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243236299,"owners_count":20258822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express-js","expressjs","mongodb","mongodb-database","node-js","nodejs"],"created_at":"2024-11-18T05:26:09.233Z","updated_at":"2025-12-26T06:42:12.133Z","avatar_url":"https://github.com/quickheaven.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The Complete MongoDB Tutorial\n\nComplete MongoDB Tutorial - The Net Ninja\n\n### 1. What is MongoDB\n\n### 2. Installing MongoDB\n\n### 3. Collections and Documents\n\n### 4. Using MongoDB Compass\n\n### 5. Using the MongoDB Shell\n```\ntest\u003e show dbs\n\nadmin       40.00 KiB\nbookstore   72.00 KiB\nconfig     108.00 KiB\nlocal       72.00 KiB\n\ntest\u003e use bookstore\n\nbookstore\u003e show collections\nbooks\nbookstore\u003e var name = \"yoshi\"\n\nbookstore\u003e name\nyoshi\n\nbookstore\u003e help\n\nbookstore\u003e exit\n```\n\n**rename a collection**\n```\ndb.books.renameCollection(\"book_v1\")\n```\n\n### 6. Adding New Documents\n```\ndb.books.insertOne({title: \"The Color of Magic\", author: \"Terry Pratchett\", pages: 300, rating: 7, genres: [\"fantasy\", \"magic\"]})\n{\n  acknowledged: true,\n  insertedId: ObjectId(\"63dd957e105ddef1505b2f1a\")\n}\n```\n**collections does not need to exists. (Ex. authors does not exists)**\n```\ndb.authors.insertOne({name: \"Brandon Sanderson\", age: 60})\n{\n  acknowledged: true,\n  insertedId: ObjectId(\"63dd95e4105ddef1505b2f1b\")\n}\n```\n\n### 7. Finding New Documents\n**print the first 20 book.**\n```\ndb.books.find()\n```\n\n**return the next 20**\n```\nit\n```\n\n**filter by author**\n```\ndb.books.find({author: \"Terry Pratchett})\n```\n\n**filter by author and ratings**\n```\ndb.books.find({author: \"Terry Pratchett\", rating: 7})\n```\n\n**filter by author and limit the return columns**\n```\ndb.books.find({author: \"Brandon Sanderson\"}, {title: 1, author: 1})\n```\n\n**no filter and limit the columns**\n```\ndb.books.find({}, {title: 1, author: 1})\n```\n\n**filter by id and one result - (in case of multiple result, it just the first one)**\n```\ndb.books.findOne({_id: ObjectId(\"63dd2828eeb9397ec4dc2368\")});\n```\n\n### 8. Sorting and Limiting Data\n**method chaining**\n```\ndb.books.find().count()\n```\n```\ndb.books.find({author: \"Brandon Sanderson\"}).count()\n```\n```\ndb.books.find().limit(3)\n```\n*sort by title 1 sort by asc, -1 desc*\n```\ndb.books.find().sort({title: 1})\n```\n\n```\ndb.books.find().sort({title: 1}).limit(3)\n```\n\n### 9. Nested Documents\n```\ndb.books.insertOne({\"title\": \"The Way of Kings\",\"author\": \"Brandon Sanderson\",\"pages\": 400,\"rating\": 9,\"genres\": [\"fantasy\"],\"reviews\": [{\"name\": \"Yoshi\",\"body\": \"Great book!!\"},{\"name\": \"mario\",\"body\": \"so so\"}]})\n```\n```\ndb.books.insertMany([])\n```\n```\n[{\n  \"title\": \"The Light Fantastic\",\n  \"author\": \"Terry Pratchett\",\n  \"pages\": 250,\n  \"rating\": 6,\n  \"genres\": [\n    \"fantasy\",\n    \"magic\"\n  ],\n  \"reviews\": [\n    {\n      \"name\": \"Luigi\",\n      \"body\": \"It was pretty good\"\n    },\n    {\n      \"name\": \"Bowser\",\n      \"body\": \"Loved It!!!\"\n    }\n  ]\n},{\n  \"title\": \"The Name of the Wind\",\n  \"author\": \"Patrick Rothfuss\",\n  \"pages\": 500,\n  \"rating\": 10,\n  \"genres\": [\n    \"fantasy\"\n  ],\n  \"reviews\": [\n    {\n      \"name\": \"Peach\",\n      \"body\": \"One of my favs\"\n    }\n  ]\n},{\n  \"title\": \"The Color of Magic\",\n  \"author\": \"Terry Pratchett\",\n  \"pages\": 350,\n  \"rating\": 8,\n  \"genres\": [\n    \"fantasy\",\n    \"magic\"\n  ],\n  \"reviews\": [\n    {\n      \"name\": \"Luigi\",\n      \"body\": \"It was OK\"\n    },\n    {\n      \"name\": \"Bowser\",\n      \"body\": \"Really good book\"\n    }\n  ]\n},{\n  \"title\": \"1984\",\n  \"author\": \"George Orwell\",\n  \"pages\": 300,\n  \"rating\": 6,\n  \"genres\": [\n    \"sci-fi\",\n    \"dystopian\"\n  ],\n  \"reviews\": [\n    {\n      \"name\": \"Peach\",\n      \"body\": \"Not my cup of tea\"\n    },\n    {\n      \"name\": \"Mario\",\n      \"body\": \"Meh\"\n    }\n  ]\n}]\n```\n\n### 10. Operators \u0026 Complex Queries\n\n```\ndb.books.find({rating: {$gt: 8}});\n\ndb.books.find({rating: {$lt: 8}});\n\ndb.books.find({rating: {$gte: 8}});\n\ndb.books.find({rating: {$lte: 8}});\n\ndb.books.find({rating: {$gt: 7}, author: \"Patrick Rothfuss\"});\n\ndb.books.find({$or: [{rating: 7}, {rating: 9}]});\n\ndb.books.find({$or: [{rating: 7}, {author: \"Terry Pratchett\"}]});\n\ndb.books.find({$or: [{pages: {$lt: 300}}, {pages: {$gt: 400}}]});\n```\n\n### 11. Using $in and $nin\n\n```\ndb.books.find({rating: {$in: [7, 8, 9]}})\n\ndb.books.find({$or: [{rating: 7}, {rating: 8}, {rating: 9}]})\n\ndb.books.find({rating: {$nin: [7, 8]}})\n```\n\n### 12 Querying Arrays\n\n**check one value**\n```\ndb.books.find({genres: \"magic\"})\n```\n**exact match - use a an array**\n```\ndb.books.find({genres: [\"magic\"]})\n```\n\n**fantasy and sci-fi needs to be in both inside the array**\n```\ndb.books.find({genres: {$all: [\"fantasy\", \"sci-fi\"]}})\n```\n```\ndb.books.find({\"reviews.name\": \"Luigi\"})\n```\n\n### 13. Deleting Documents\n```\ndb.books.deleteOne({_id: ObjectId(\"63dedb3439074017ea39236b\")})\n\ndb.books.deleteMany({author: \"Terry Pratchett\"})\n```\n\n### 14. Update Documents\n```\ndb.books.updateOne({_id: ObjectId('63ded5841c406856fc87e8e2')}, {$set: {rating: 8, paging: 360}})\n\ndb.books.updateMany({author: \"Terry Pratchett\"}, {$set: {author: \"Terry Pratchet\"}})\n\ndb.books.updateOne({_id: ObjectId(\"63ded5841c406856fc87e8e3\")}, {$inc: {pages: 2}})\n\ndb.books.updateOne({_id: ObjectId(\"63ded5841c406856fc87e8e3\")}, {$inc: {pages: -2}})\n\ndb.books.updateOne({_id: ObjectId(\"63ded5841c406856fc87e8e3\")}, {$pull: {\"genres\": \"fantasy\"}})\n\ndb.books.updateOne({_id: ObjectId(\"63ded5841c406856fc87e8e3\")}, {$push: {\"genres\": \"fantasy\"}})\n\ndb.books.updateOne({_id: ObjectId(\"63ded5841c406856fc87e8e3\")}, {$push: {\"genres\": {$each: [\"1\", \"2\"]}}})\n```\n\n### 15. MongoDB Drivers\n```\nnpm init\n\nnpm install express --save\n\ncreate app.js\n\nnpm install -g nodemon\n```\n\n*have to setup the path in windows.*\n```\nnodemon app \n\nnpx nodemon app \n\nnpm install mongodb --save\n```\n\n### 16. Indexes\n```\ndb.books.find({rating: 8}).explain('executionStats')\n\ndb.books.createIndex({rating: 8 })\n\ndb.books.getIndexes()\n\ndb.books.dropIndex({rating: 8})\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquickheaven%2Fcomplete-mongo-db-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquickheaven%2Fcomplete-mongo-db-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquickheaven%2Fcomplete-mongo-db-tutorial/lists"}