Skip to main content

Setting up a NoSQL database with MongoDB

This post details the setup process for a NoSQL database with MongoDB. Firstly, go to the MongoDB website and navigate to the Download Center. Download the correct version and run the installer. For ease of access, customise the location to be on the C drive root.

In the command line, go to the bin within the mongodb folder. Return the below in order to set up the directory and logging.


After hitting enter, the following will be displayed. The MongoDB service is now started and we can go ahead and view and customise some no-SQL databases.


Returning "show dbs" in the command line will display the current databases. We can see we have a local and admin database. To create a new database, for example "mycustomers" we have to return "use mycustomers". If the "mycustomers" database already existed, then the "use mycustomers" command would not create a new database, but instead make "mycustomers" the active database. Users can be created for the database by simply using "db.createUser(...)".


In SQL databases we have tables and records, in MongoDB we have collections and documents. To create a new collection, "db.createCollection('...')" is used, as seen below. The "show collections" command can be used to display all existing collections on the active database. To insert a document into a collection the command "db.customers.insert(...)" can be used, in this instance where the collection is "customers". To show all documents for a collection "db.customers.find()" can be used, again assuming "customers" is the collection.


The GUI

Also available on the MongoDB site is a GUI called Compass, which makes it simpler to view and edit a MongoDB database. The following screenshot shows how collections are displayed.


Below shows the "John Doe" document in the "customers" collection, which itself is in the "mycustomers" database.


Although the GUI does make it easier to view and edit databases, I think it is still important to get a good understanding of the command line interface first because, as is the case with every GUI, it has limitations.

Comments