{"id":18585194,"url":"https://github.com/programmierenm/mongodb-cheat-sheet","last_synced_at":"2025-05-16T06:08:40.691Z","repository":{"id":153346379,"uuid":"452978298","full_name":"ProgrammierenM/mongodb-cheat-sheet","owner":"ProgrammierenM","description":"MongoDB Cheat Sheet - Alle wichtigen Befehle um Daten zu lesen, zu schreiben, zu aktualisieren und vieles mehr.","archived":false,"fork":false,"pushed_at":"2022-01-28T11:43:20.000Z","size":3,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-17T16:52:27.343Z","etag":null,"topics":["mongodb","mongodb-database"],"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/ProgrammierenM.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-01-28T07:34:21.000Z","updated_at":"2024-08-18T12:34:17.000Z","dependencies_parsed_at":"2023-05-05T22:30:50.866Z","dependency_job_id":null,"html_url":"https://github.com/ProgrammierenM/mongodb-cheat-sheet","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/ProgrammierenM%2Fmongodb-cheat-sheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammierenM%2Fmongodb-cheat-sheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammierenM%2Fmongodb-cheat-sheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProgrammierenM%2Fmongodb-cheat-sheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ProgrammierenM","download_url":"https://codeload.github.com/ProgrammierenM/mongodb-cheat-sheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478193,"owners_count":22077676,"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":["mongodb","mongodb-database"],"created_at":"2024-11-07T00:31:46.376Z","updated_at":"2025-05-16T06:08:35.683Z","avatar_url":"https://github.com/ProgrammierenM.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# MongoDB Tutorial\n\nMongoDB Tutorial Deutsch für Anfänger. Mit MongoDB als NoSQL Datenbank kannst du deine Daten direkt als Objekt im JSON Format persistieren und auch so wieder auslesen. Ich zeige dir was du alles brauchst und stelle dir alle wichtigen Befehle in der MongoDB Shell vor. Happy Coding!\n\n[Tutorial auf YouTube anschauen](https://youtu.be/jpTNn4zkMKY)\n\n[![Tutorial bei Youtube](http://img.youtube.com/vi/jpTNn4zkMKY/0.jpg)](https://youtu.be/jpTNn4zkMKY)\n\n## Vernetze dich:\n\n[\u003cimg align=\"left\" alt=\"programmierenmitmario.de\" width=\"22px\" src=\"https://raw.githubusercontent.com/iconic/open-iconic/master/svg/globe.svg\" /\u003e][website]\n[\u003cimg align=\"left\" alt=\"programmierenmitmario | YouTube\" width=\"22px\" src=\"https://cdn.jsdelivr.net/npm/simple-icons@v3/icons/youtube.svg\" /\u003e][youtube]\n[\u003cimg align=\"left\" alt=\"programmierenmitmario | Twitter\" width=\"22px\" src=\"https://cdn.jsdelivr.net/npm/simple-icons@v3/icons/twitter.svg\" /\u003e][twitter]\n[\u003cimg align=\"left\" alt=\"programmierenmitmario | Instagram\" width=\"22px\" src=\"https://cdn.jsdelivr.net/npm/simple-icons@v3/icons/instagram.svg\" /\u003e][instagram]\n\u003cbr\u003e\n\u003cbr\u003e\n\n## MongoDB Cheat Sheet\n\n### Alle Datenbanken anzeigen\n\n\u003cpre\u003e\nshow dbs\n\u003c/pre\u003e\n\n### Aktualle Datenbank anzeigen\n\n\u003cpre\u003e\ndb\n\u003c/pre\u003e\n\n### Datenbank verwenden/anlegen\n\n\u003cpre\u003e\nuse tutorial\n\u003c/pre\u003e\n\n### Datenbank löschen\n\n\u003cpre\u003e\ndb.dropDatabase('tutorial')\n\u003c/pre\u003e\n\n## Collections\n\n### Neue Collection anlegen\n\n\u003cpre\u003e\ndb.createCollection('products')\n\u003c/pre\u003e\n\n### Alle Collections anzeigen\n\n\u003cpre\u003e\nshow collections\n\u003c/pre\u003e\n\n### Collection löschen\n\n\u003cpre\u003e\ndb.products.drop()\n\u003c/pre\u003e\n\n## Documents anlegen\n\n### Ein neues Document hinzufügen\n\n\u003cpre\u003e\ndb.products.insertOne(\n  {\n    name: \"Banane\",\n    price: 0.99,\n    category: 'Obst',\n    views: 16\n  }\n)\n\u003c/pre\u003e\n\n### Mehrere Documents hinzufügen\n\n\u003cpre\u003e\ndb.products.insertMany(\n  [\n    {\n      name: \"Apfel\",\n      price: 0.60,\n      category: 'Obst',\n      views: 2\n    },\n    {\n      name: \"Apfel Neu\",\n      price: 0.80,\n      category: 'Obst',\n      views: 10\n    },\n    {\n      name: \"Kiwi\",\n      price: 1.19,\n      category: 'Obst',\n      views: 0,\n      ratings: [\n        { user: 'Paul', stars: 4},\n        { user: 'Tom', stars: 5},\n        { user: 'Max', stars: 3}\n      ]\n    }\n  ]\n)\n\u003c/pre\u003e\n\n## Documents auslesen\n\n### Alle Documents aus der Collection anzeigen\n\n\u003cpre\u003e\ndb.products.find()\n\u003c/pre\u003e\n\n### Ergebnisse formatiert\n\n\u003cpre\u003e\ndb.products.find().pretty()\n\u003c/pre\u003e\n\n### Ergebnisse filtern\n\n\u003cpre\u003e\ndb.products.find({ name: 'Apfel' })\n\u003c/pre\u003e\n\n### Ergebnisse sortieren\n\n\u003cpre\u003e\ndb.products.find().sort({ name: 1 })\ndb.products.find().sort({ name: -1 })\n\u003c/pre\u003e\n\n### Ergebnisse zählen\n\n\u003cpre\u003e\ndb.products.find().count()\ndb.products.countDocuments()\n\u003c/pre\u003e\n\n### Ergebnisse limitieren\n\n\u003cpre\u003e\ndb.products.find().limit(2)\n\u003c/pre\u003e\n\n### Verkettung mehrerer Funktionen\n\n\u003cpre\u003e\ndb.products.find().limit(2).sort({ price: 1 })\n\u003c/pre\u003e\n\n### ForEach Schleife\n\n\u003cpre\u003e\ndb.products.find().forEach(function(doc) {\n  print(\"Produkt: \" + doc.name)\n})\n\u003c/pre\u003e\n\n### Ergebnisse nach Größer/Kleiner filtern\n\n\u003cpre\u003e\ndb.products.find({ price: { $gt: 1 } })\ndb.products.find({ price: { $gte: 0.99 } })\ndb.products.find({ price: { $lt: 0.99 } })\ndb.products.find({ price: { $lte: 0.99 } })\n\u003c/pre\u003e\n\n### Feld indexieren\n\n\u003cpre\u003e\ndb.products.createIndex(\n  { name: 'text' },\n  { default_language: \"german\" }\n)\n\u003c/pre\u003e\n\n### Alle Indexes anzeigen\n\n\u003cpre\u003e\ndb.products.getIndexes()\n\u003c/pre\u003e\n\n### Index löschen\n\n\u003cpre\u003e\ndb.products.dropIndex('name_text')\n\u003c/pre\u003e\n\n### Textsuche\n\n\u003cpre\u003e\ndb.products.find({\n  $text: {\n    $search: \"Apfel\"\n  }\n})\n\u003c/pre\u003e\n\n### Nur ein Ergebnis\n\n\u003cpre\u003e\ndb.products.findOne({ category: 'Obst' })\n\u003c/pre\u003e\n\n### Ergebnisse gefiltert und mit bestimmten Feldern\n\n\u003cpre\u003e\ndb.products.find({ category: 'Obst' }, {\n  name: 1,\n  price: 1\n})\n\u003c/pre\u003e\n\n### Alle Ergebnisse mit bestimmten Feldern\n\n\u003cpre\u003e\ndb.products.find({}, {\n  name: 1,\n  price: 1\n})\n\u003c/pre\u003e\n\n### Alle Ergebnisse ohne bestimmte Felder\n\n\u003cpre\u003e\ndb.products.find({}, {\n  ratings: 0,\n  date: 0\n})\n\u003c/pre\u003e\n\n## Documents updaten\n\n### Ein Document aktualisieren\n\n\u003cpre\u003e\ndb.products.updateOne({ name: \"Banane\" },\n{\n  $set: {\n    price: 1.29\n  }\n})\n\u003c/pre\u003e\n\n### Ein Document aktualisieren/hinzufügen\n\n\u003cpre\u003e\ndb.products.updateOne({ name: 'Gurke' },\n{\n  $set: {\n    price: 0.5 ,\n    category: 'Gemüse',\n    views: 0\n  }\n},\n{\n  upsert: true\n})\n\u003c/pre\u003e\n\n### Viele Documents aktualisieren\n\n\u003cpre\u003e\ndb.products.updateMany({ category: \"Obst\" },\n{\n  $set: {\n    price: 0.2\n  }\n})\n\u003c/pre\u003e\n\n### Einen Wert erhöhen\n\n\u003cpre\u003e\ndb.products.updateOne({ name: 'Gurke' },\n{\n  $inc: {\n    views: 1\n  }\n})\n\u003c/pre\u003e\n\n### Ein Feld umbenennen\n\n\u003cpre\u003e\ndb.products.update({ name: 'Gurke' },\n{\n  $rename: {\n    views: 'likes'\n  }\n})\n\u003c/pre\u003e\n\n## Aggregates\n\n### Daten aus Collections verarbeiten\n\n\u003cpre\u003e\ndb.products.aggregate([\n  {\n    $match: {\n      price: { $lt: 0.99 }\n    }\n  },\n  {\n    $group: {\n      _id: \"$category\",\n      total_views: { $sum: \"$views\"}\n    }\n  }\n])\n\u003c/pre\u003e\n\n## Documents löschen\n\n### Ein Document löschen\n\n\u003cpre\u003e\ndb.products.deleteOne({ name: 'Gurke' })\n\u003c/pre\u003e\n\n### Viele Documents löschen\n\n\u003cpre\u003e\ndb.products.deleteMany({ category: 'Obst' })\n\u003c/pre\u003e\n\n## License\n\n[MIT](LICENSE)\n\n[website]: http://programmierenmitmario.de\n[twitter]: https://twitter.com/programmierenm\n[youtube]: https://youtube.com/programmierenmitmario\n[instagram]: https://instagram.com/programmierenm\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprogrammierenm%2Fmongodb-cheat-sheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprogrammierenm%2Fmongodb-cheat-sheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprogrammierenm%2Fmongodb-cheat-sheet/lists"}