{"id":18688552,"url":"https://github.com/mian-ali/mongodb-cheatsheet","last_synced_at":"2026-04-18T00:07:31.788Z","repository":{"id":104243732,"uuid":"538815252","full_name":"mian-ali/mongoDB-cheatsheet","owner":"mian-ali","description":"we will see a comprehensive list of all the MongoDB commands you will ever need as a MongoDB beginner. This list covers almost all the most used commands in MongoDB.","archived":false,"fork":false,"pushed_at":"2024-03-18T00:08:57.000Z","size":12,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-18T20:36:30.334Z","etag":null,"topics":["database","mongo","mongod","mongodb","mongodb-atlas","mongodb-database","mongodb-sheat-sheet","mongoose","sheatsheet"],"latest_commit_sha":null,"homepage":"","language":null,"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/mian-ali.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":"2022-09-20T04:54:06.000Z","updated_at":"2024-07-31T19:11:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"1847fbc5-ab3a-428e-9a53-1793e328a76a","html_url":"https://github.com/mian-ali/mongoDB-cheatsheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mian-ali/mongoDB-cheatsheet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mian-ali%2FmongoDB-cheatsheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mian-ali%2FmongoDB-cheatsheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mian-ali%2FmongoDB-cheatsheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mian-ali%2FmongoDB-cheatsheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mian-ali","download_url":"https://codeload.github.com/mian-ali/mongoDB-cheatsheet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mian-ali%2FmongoDB-cheatsheet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269409315,"owners_count":24412140,"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","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["database","mongo","mongod","mongodb","mongodb-atlas","mongodb-database","mongodb-sheat-sheet","mongoose","sheatsheet"],"created_at":"2024-11-07T10:37:13.050Z","updated_at":"2026-04-18T00:07:26.743Z","avatar_url":"https://github.com/mian-ali.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# MongoDB CheatSheet\n\n### All MongoDB commands `MongoDb Cheatsheet`\n\nAs a beginner in MongoDB, you might find it helpful to have a comprehensive list of all the necessary commands. This list includes almost all of the most commonly used commands in MongoDB. For the purpose of this guide, let us assume that you are working within a collection named `comments` on a MongoDB database of your choice.\n\n### 1. Database Commands\nView all databases\n```js\nshow dbs\n```\nCreate a new or switch databases \n```js \nuse dbName\n```\nView current Database\n\n```js\ndb\n```\nDelete Database \n\n```js\ndb.dropDatabase()\n```\n### 2. Collection Commands\nShow Collections\n```js\nshow collections\n```\nCreate a collection named `comments`\n```js\ndb.createCollection('comments')\n```\nDrop a collection named `comments`\n```js\ndb.comments.drop()\n```\n### 3. Row(Document) Commands\nShow all Rows in a Collection \n```js\ndb.comments.find()\n```\nShow all Rows in a Collection (Prettified)\n```js\ndb.comments.find().pretty()\n```\nFind the first row matching the object\n```js\ndb.comments.findOne({name: 'Ahmad'})\n```\nInsert One Row\n```js\ndb.comments.insert({\n    'name': 'Ahmad',\n    'tech_lang': 'JavaScript',\n    'member_since': 5\n })\n```\nInsert many Rows\n```js\ndb.comments.insertMany([{\n    'name': 'Ahmad',\n    'tech_lang': 'JavaScript',\n    'member_since': 5\n    }, \n    {'name': 'test',\n    'tech_lang': 'Python',\n    'member_since': 3\n    },\n    {'name': 'ali',\n    'tech_lang': 'Java',\n    'member_since': 4\n}])\n\n```\nSearch in a MongoDb Database\n```js\ndb.comments.find({tech_lang:'Python'})\n```\nLimit the number of rows in output\n```js\ndb.comments.find().limit(2)\n```\nCount the number of rows in the output\n```js\ndb.comments.find().count()\n```\nUpdate a row\n```js\ndb.comments.updateOne({name: 'Ali'},\n{$set: {'name': 'Ahmad',\n    'tech_lang': 'JavaScript',\n    'member_since': 51\n}}, {upsert: true})\n```\nMongodb Increment Operator\n```js\ndb.comments.update({name: 'Admin User'},\n{$inc:{\n    member_since: 2\n}})\n```\nMongodb Rename Operator\n```js\ndb.comments.update({name: 'Admin'},\n{$rename:{\n    member_since: 'member'\n}})\n```\nDelete Row \n```js\ndb.comments.remove({name: 'Ahmad'})\n```\nLess than/Greater than/ Less than or Eq/Greater than or Eq\n```js\ndb.comments.find({member_since: {$lt: 90}})\n```\n```js \ndb.comments.find({member_since: {$lte: 90}})\n```\n```js\ndb.comments.find({member_since: {$gt: 90}})\n```\n```js\ndb.comments.find({member_since: {$gte: 90}})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmian-ali%2Fmongodb-cheatsheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmian-ali%2Fmongodb-cheatsheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmian-ali%2Fmongodb-cheatsheet/lists"}