mongosh in MongoDB?mongosh is the interactive command-line shell for MongoDB. It lets you connect to your database, run commands, and see results immediately.
mongosh?Simply type mongosh in your terminal and press Enter. It connects to mongodb://localhost:27017 by default.
mongosh?Use show dbs to see all databases on the connected MongoDB server.
mongosh?Use use <databaseName>. For example, use mydb switches to the database named mydb.
mongosh?Use db.collectionName.insertOne({key: 'value'}). For example, db.users.insertOne({name: 'Alice', age: 25}) adds a user document.
show dbs do in mongosh?show dbs lists all databases available on the connected MongoDB server.
shop in mongosh?The command use shop switches your session to the shop database.
products collection?db.products.insertOne({name: 'Pen'}) correctly inserts a single document into the products collection.
mongosh connects to if no parameters are given?By default, mongosh connects to mongodb://localhost:27017.
The command show collections lists all collections in the current database.
mongosh and switch to a database named testdb.customers using mongosh.