Entwickler-Tools
MongoDB Guide
Nutze ein Entwickler-Tool für Daten, Code oder Nachschlage-Workflows.
| Category | Command | Explanation | |
|---|---|---|---|
| Connection | mongosh | Connect to a local MongoDB server. | |
| Connection | mongosh "mongodb://localhost:27017/app_db" | Connect to a specific database with a connection string. | |
| Database | show dbs | List databases. | |
| Database | use app_db | Switch to a database. It is created when data is inserted. | |
| Collection | show collections | List collections in the current database. | |
| Collection | db.createCollection("users") | Create a collection explicitly. | |
| Insert | db.users.insertOne({ email: "demo@example.com", createdAt: new Date() }) | Insert one document. | |
| Insert | db.users.insertMany([{ email: "a@example.com" }, { email: "b@example.com" }]) | Insert multiple documents. | |
| Read | db.users.find({ email: /@example.com$/ }).sort({ createdAt: -1 }).limit(20) | Query, sort, and limit documents. | |
| Read | db.users.findOne({ email: "demo@example.com" }) | Find a single matching document. | |
| Update | db.users.updateOne({ email: "demo@example.com" }, { $set: { active: true } }) | Update one matching document. | |
| Update | db.users.updateMany({ active: { $exists: false } }, { $set: { active: true } }) | Update many matching documents. | |
| Delete | db.users.deleteOne({ email: "demo@example.com" }) | Delete one matching document. | |
| Delete | db.users.deleteMany({ active: false }) | Delete many matching documents. | |
| Index | db.users.createIndex({ email: 1 }, { unique: true }) | Create a unique ascending index. | |
| Index | db.users.getIndexes() | List collection indexes. | |
| Aggregation | db.orders.aggregate([{ $group: { _id: "$userId", total: { $sum: "$total" } } }]) | Group documents and compute totals. | |
| Count | db.users.countDocuments({ active: true }) | Count matching documents. | |
| Backup | mongodump --db app_db --out ./backup | Export a database backup. | |
| Restore | mongorestore --db app_db ./backup/app_db | Restore a dumped database. |
Concepts
MongoDB basics
| Concept | Meaning |
|---|---|
| Document | A JSON-like BSON object stored in a collection. |
| Collection | A group of documents, roughly comparable to a table but schema-flexible. |
| Database | A namespace containing collections and indexes. |
| ObjectId | The common default value for the _id primary key. |
| Index | A data structure that speeds up reads and supports uniqueness constraints. |
| Aggregation | A pipeline for transforming, grouping, filtering, and joining document data. |
FAQ
Häufige Fragen
Wofür wird MongoDB Guide verwendet?
MongoDB Guide hilft, diesen Workflow direkt im Browser abzuschließen.
Brauche ich ein Konto?
Nein. NovaKit-Tools sind für die direkte Nutzung ohne Konto gedacht.
Kann ich Ergebnisse kopieren oder herunterladen?
Wenn Ausgaben entstehen, bietet die Seite Kopieren-, Download- oder Exportaktionen.
Verwandte Tools