What is Mongo Shell?

What is Mongo Shell?

 What is Mongo Shell?


MongoDB provides an interactive mongo shell based on JavaScript. This provides a command-line interface between users and MongoDB databases. You can find the best tutorials here for the installation of the MongoDB server on Linux operating systems.

What is mongo Shell?

Mongo shell is a command-line interface between user and database. You can connect to your MongoDB server using this shell and manage your databases and collections. You can also perform the administrative tasks on MongoDB.

Connect to MongoDB Shell

Type mongo on your system terminal. It will automatically connect to your local MongoDB server running on port 27017.

mongo

MongoDB shell version v3.4.4
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.4
>

You need to specify the hostname to connect the remote database. Also, specify the port if MongoDB is running on a different port.

> mongo --host 10.10.8.1 --port 27017

MongoDB shell version: 2.6.4
connecting to: 10.10.8.1:27017/test

Exit the mongo Shell

Use quit() function or press CTRL+C to quit from the mongo shell.

> quit()

Working with MongoDB Shell

The ongoing tutorial is based on mongo shell. Let’s do some basic tasks with mongo shell. Open mongo shell as shown in the above commands and run the following commands.

Arithmetic operations:

> 22 + 10          ## Output: 22
> 22 * 10          ## Output: 220

Using variables:

> i=22              ## Output: 22
> j=10              ## Output: 220
> i * j             ## Output: 220
Reactions

Post a Comment

0 Comments

close