MongoDB
MongoDB shell commands for CRUD operations, aggregation pipelines, indexing, and database administration.
83 commands
Browse by Topic
Getting Started
Quick setup and installation
Connection
Connecting to MongoDB
Database
Database operations
CRUD
Insert, find, update, delete
Query
Query operators
Indexes
Index management
Aggregation
Aggregation pipeline
Backup/Restore
mongodump & mongorestore
Change Streams
Real-time change monitoring
Transactions
Multi-document ACID transactions
Time Series
Time series collections
Performance
Performance monitoring & ops
Users & Roles
User management, authentication & authorization
Run MongoDB with Docker
Start MongoDB server in a Docker container on port 27017
Connect with mongosh
Open interactive MongoDB shell in the running container
Show databases
List all databases in MongoDB
Connect to MongoDB
Connect to local MongoDB instance.
Connect with auth
Connect with authentication.
Connect to Atlas
Connect to MongoDB Atlas cluster.
Execute and exit
Run command and exit.
Run script file
Execute JavaScript file.
Show databases
List all databases.
Use database
Switch to database (creates if not exists).
Current database
Show current database.
Show collections
List collections in current database.
Create collection
Create a new collection.
Drop collection
Delete a collection.
Drop database
Delete current database.
Database stats
Show database statistics.
Insert one
Insert a single document.
Insert many
Insert multiple documents.
Find all
Retrieve all documents.
Find with filter
Find documents matching criteria.
Find one
Retrieve first matching document.
Update one
Update first matching document.
Update many
Update all matching documents.
Delete one
Delete first matching document.
Delete many
Delete all matching documents.
Replace one
Replace entire document.
Comparison operators
Use $gt, $gte, $lt, $lte, $eq, $ne.
Logical AND
Match all conditions.
Logical OR
Match any condition.
In array
Match any value in array.
Regex search
Pattern matching with regex.
Field exists
Check if field exists.
Projection
Select specific fields to return.
Sort and limit
Sort descending and limit results.
Create index
Create ascending index on field.
Unique index
Create unique constraint index.
Compound index
Create index on multiple fields.
Text index
Create full-text search index.
List indexes
Show all indexes on collection.
Drop index
Remove an index by name.
Basic aggregation
Match and group with sum.
Count by group
Count documents per group.
Lookup (join)
Join with another collection.
Unwind array
Flatten array and aggregate.
Project fields
Transform document structure.
Dump database
Export database to BSON files.
Dump collection
Export specific collection.
Dump with compression
Export as compressed archive.
Restore database
Import from BSON dump.
Restore from archive
Restore from compressed archive.
Export to JSON
Export collection to JSON file.
Import from JSON
Import from JSON file.
Import CSV
Import from CSV with headers.
Watch collection changes
Monitor real-time changes to a collection.
Watch database changes
Monitor all changes across entire database.
Filtered change stream
Watch only insert operations on collection.
Close change stream
Close active change stream connection.
Start session
Initialize client session for transactions.
Begin transaction
Start multi-document ACID transaction.
Commit transaction
Persist all transaction changes.
Abort transaction
Rollback transaction changes.
Create time series collection
Create optimized collection for time-stamped data.
Collection statistics
View detailed collection storage and index info.
Validate collection
Perform full integrity check on collection.
Total index size
Calculate total storage used by all indexes.
Current operations
Show all currently running database operations.
Kill operation
Terminate a long-running or stuck operation.
Discussion
Loading comments...