MongoDB: Installing a MongoDB client on Ubuntu

In order to communicate with MongoDB using its default TCP protocol on port 27017, you will need a MongoDB client.  There are many language bindings available, but in this article we’ll focus on the client available from the “mongodb-org-shell” Debian package.

Installing

Import the public key for the packages.

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

Add the Mongo repository, then install the Mongo tools package.

$ echo "deb http://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

$ sudo apt-get update

$ sudo apt-get install mongodb-org-tools

Validating

Check the installation version.

$ mongo --version

Then connect to a MongoDB server using the following syntax.

$ mongo <FQDN>:<PORT>/<database> -u <user> -p <password>

 

REFERENCES

https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-ubuntu/

https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/ (TCP protocol)

https://docs.mongodb.com/manual/reference/default-mongodb-port/

https://testlio.com/blog/handy-tips-for-mongodb-shell-queries/

NOTES

Default port is 27017

If HTTP REST interface is enabled, default port is 28017