Installing and Getting Started with MongoDb on Linux Ubuntu
Getting started with MongoDb, a NoSQL database system

In this guide we will take a look at installing MongoDb and getting started with some basic query commands.
MongoDb is an open-source cross platform NoSQL or document-oriented database system. The database information is represented as JSON schemas.
NoSQL Databases, like MongoDb, are popular among software engineers because of their object-oriented manner of representing information.
Install MongoDb
You can easily install MongoDb from the command line. First update your package.
$ sudo apt-get update
Then install MongoDb with the command below.
$ sudo apt-get install mongodb
MongoDb Service
MongoDb runs a service in the background. Here are some helpful command for working with the MongoDb service.
Check status
$ sudo service mongodb status
The green light shows that the service is active and running. In addition, the active property also shows that the service is running.

Start service
$ sudo service mongodb start
Stop service
$ sudo service mongodb stop
Restart service
$ sudo service mongodb restart
Mongo Shell
The mongo shell is a command line interface for interacting with the database system. Within the mongo shell you can query , update or conduct other CRUD operations on the database.
In addition, the mongo shell allows you to carry out administrative tasks.
To Access the mongo shell simply run the following command.
$ mongo
To exit the mongo shell, run the following command within the mongo shell:
exit;
Interacting with the Database
In MongoDb, a database is simply a physical container for collections.
Note: To interact with the database from the command line you have to be in the mongo shell, as highlighted in the section above.
Now that you are within the mongo shell you can list available databases on the system using the following command.
show dbs;
In this case, I have four databases on my system.

Note: If a database has no collections it will not be listed under available databases.
To interact with a specific database, for example to interact with the contact-manager database. Run the following command.
use contact-manager;
Create a Database
To create a new database within MongoDb, utilize the use command. For example, to create a database named contact-manager, run the following command.
use contact-manager;
In addition to creating a data, the use command is also used for selecting a database to interact with.
If the database name exists, MongoDb will simply select it for interaction, otherwise a new database is created.
Show Active database
To show the current active database, run the command
db;
Switch Database
To choose another database to interact with, utilize the use command.
For example, to switch to the contact-manger database.
use contact-manager;
Collections
A collection is simply a grouping of several MongoDb documents. It’s the equivalent of a table in traditional relational database management systems (RDBMS).
Show collections
First make sure that you select a database to interact with as defined in the section above.
show collections;
In my case the contact-manager database has two collections: contacts and users.
List items in a collection
To list the items in a collection, run the find() method on the collection. The syntax is as follows db.collection_name.find(). For example, to list all items in the contacts collection, run the command.
db.contacts.find();
Use the pretty() method for a more readable output.
db.users.find().pretty();

Insert a record
To insert a record in a collection, you can use the insert() method on the collection. You supply the items to insert as a json object argument within the insert method.
For example to insert a new user record in the users collection, run the following command.
db.users.insert({ "userame": "Tadala", "admin": true, "pwd":"xSH$#4x"});

The output shows that one record was inserted in the collection.
In addition to creating the collection, MongoDb will automatically generate a unique id for the record created.
Update record
To update a record in a collection, use the update() method. You supply the property you want to update and the new object as arguments in the update method.
db.users.update({"username":"Tadala"},{$set:{"username":"Tehillah Linweka"}});
Delete a record
To delete a record from a collection, use the remove() method. You pass in the deletion criteria as an argument to the remove method.
For example to remove the user record we created above, run the following command.
db.users.remove({"username":"Tehillah Linweka"})
Help
Last but not least, the mongo shell has in-built help, so whenever you get stuck just run the help command as follows.
help
Conclusion
We have successfully installed MongoDB and run some of the commonly used commands.
MongoDb is a highly robust database system that is very scalable and lightweight.