MongoDB Shell Introduction: Simple Database Operations via Command Line

The MongoDB Shell is a JavaScript-based interactive command-line tool for directly operating MongoDB databases, suitable for beginners. After installing MongoDB, simply type "mongo" in the terminal to start the Shell. Basic operations include: using `db` to view the current database, `use database_name` to switch (creates the database automatically if it doesn’t exist when inserting data); for remote connections, use `mongo --host remote_IP --port port` (default port is 27017). Data operations: Insert a single document with `insertOne({...})` (creates the collection automatically); query with `find()`/`findOne()` (use `find().pretty()` for formatted output); update with `updateOne()` (modify fields using `$set`) or `updateMany()` (increment with `$inc`); delete with `deleteOne()` or `deleteMany()`. Management operations: `show dbs` lists databases; `db.dropDatabase()` deletes the current database; `db.collection_name.drop()` deletes a collection. Advanced tips include `countDocuments()` for counting and `limit()` for restricting results. It is recommended to practice more and consult the official documentation for complex operations.

Read More