How to set up your own NoSQL database

Due to its simple queries and flexible data models, NoSQL is steadily gaining popularity in the software industry. Are you also developing an application using NoSQL as a database option? Next, to test your application on your local server, you need to set up a NoSQL database on your PC.

Some popular NoSQL databases include MongoDB, Cassandra, CouchDB, CouchBase, Riak, and HBase. But how do you create one? Here’s how.

What is a NoSQL database?

Also known as non-SQL, NoSQL is a non-relational database design based on collections and documents rather than tables and rows like in SQL.

In NoSQL, a collection is an aggregation of documents. These documents are individual JSON objects available as key-value pairs. So, a collection in NoSQL can contain a particular group of information. For example, it could be a collection of user data.

However, the documents in a collection are independent of each other and do not have a defined structure. As a result, everyone’s data may be different in length and content.

This flexibility makes it easy to add additional data to some documents while leaving out others, all without encountering errors or zero-value constraints when querying or entering data. In turn, regardless of the length of the document or the type of content, you can always select specific information in each of them.

Requirements for setting up a NoSQL database

The configuration requirements of a NoSQL database sometimes depend on the NoSQL technology you have chosen. But installing one is pretty easy.

CouchDB and MongoDB, for example, only require a few installations, and you’re good to go.


Related: How to Connect Your Flask Application with CouchDB: A NoSQL Database

We are going to base this tutorial on MongoDB, as it is the most widely used NoSQL database management system.

Ultimately, as with many NoSQL databases, you need to install MongoDB’s dedicated server to run your database. This facilitates communication between your application and the database.

While not required, you can also download MongoDB Compass, a more user-friendly tool for viewing and managing collections and documents in a dedicated graphical interface.

If you prefer to manage databases in a command line interface, you can also configure MongoDB shell commands in your terminal.

Main differences between SQL and NoSQL

SQL and NoSQL have specific use cases. But what are the main differences between them?

  1. Because SQL columns point to related cells (data points), each key in a document also points to specific information (value).
  2. While SQL links tables in an object-to-relational mapping (ORM) system, NoSQL uses object document mapping (ODM) to link collections in a database.
  3. Data stored in NoSQL databases is readily available as unstructured JSON objects. SQL stores information in more organized data files.
  4. Unlike SQL, which has rigid schemas, NoSQL schemas are more flexible. Plus, NoSQL doesn’t require tedious joins. So SQL queries are sometimes pale compared to NoSQL queries.

How to configure MongoDB database on Windows

As mentioned earlier, you need to download and install a few files for MongoDB to run on your PC. But more importantly, you will need to install the MongoDB server.

To get started, follow these instructions:

Go to Downloading MongoDB to download and install the community version of the MongoDB server.

To note: Once you are on the download page, expand the MongoDB Community Server tongue.

MongoDB download page

In the sidebar on the right, click To download to get the compatible version for your operating system.

MongoDB server download page

Once the download is complete, open the installer file to start installing MongoDB Server on your PC:

Click on Following and accept the license agreement. Then click Following.

MongoDB Server Installation License Agreement

In the next window, copy the path of the file to the Data directory field and paste it somewhere you can edit it.

MongoDB server installation file path field

To replace The data in the path copied with trash can.

For example, if the path copied initially is:

C:Program FilesMongoDBServer5.0data

Replace this with:

C:Program FilesMongoDBServer5.0bin

Once done, go back to the installation process and click on Following.

In the next step, select Complete to use the default installation.

Full MongoDB server installation and custom options

Leave on Install the MongoDB compass box checked to install the GUI tool. Then click Following.

MongoDB server installation step

To select To install to install MongoDB server on your PC.

MongoDB server installation process

Configure MongoDB Shell commands in your Windows terminal

For Windows operating system, you need to add the path you copied earlier in the system variable. This allows you to run MongoDB commands from the terminal.

To do this:

Open a folder on your PC. In the left bar, right click This PC. Then select Properties. This brings you to On menu.

You can also click on the Windows icon or press the Windows key on your keyboard. Click it Settings icon. To select System. Scroll down and select the On option.

Look to the right and select Advanced system settings.

Windows Settings About

In the next window, click on Environment variables.

Windows settings environment variables

Double click Path below System variables.

Windows system variables

Click on New. Paste the modified path in the field provided. Then click Okay in all windows to finish adding MongoDB to your system variable.

System variable add a new path

Now open your terminal and type the following command:

mongo --version

If the above command returns MongoDB version installed, it means that you have successfully installed MongoDB server on your local machine.

Adding the MongoDB bin path to your environment variables allows you to run MongoDB commands in your terminal without installing the dedicated MongoDB shell.

Related: How to Perform CRUD Operations in MongoDB

You can also search MongoDB Compass through your PC’s search bar to make sure you have it installed with the server.

If you cannot find MongoDB Compass on your PC, you can install it separately by downloading the installation file from the MongoDB compass download page.

Configure MongoDB on Mac

You can install MongoDB on Mac OS using the Homebrew option. Before you start, make sure you have the latest version of Homebrew on your Mac.

If you do not have Homebrew installed, run this command in your Mac terminal to install the latest version:

/bin/bash -c "$(curl -fsSL"

Update brew rather:

$ brew update

Now go ahead and install MongoDB Server by running the following command in your terminal:

$ brew install mongodb-community

To start the server:

$ brew services start mongodb-community

Related: How to Create a Database and Collection in MongoDB

That’s it. You can now use MongoDB as the database of choice when building apps on your PC. And if you install MongoDB Compass, you can view databases and collections there.

Get your NoSQL database running

As we mentioned before, there is no shortage of NoSQL databases. You might want to consider the simplicity and community support before creating one. However, there may be some differences in their setup processes. But running a NoSQL database on a local machine often follows a similar installation pattern. The steps outlined above will give you the basic knowledge you need to install any NoSQL database.

NoSQL vs SQL databases
SQL vs NoSQL: What’s the Best Database for Your Next Project?

Choosing a database type can be tricky. Should you choose SQL or NoSQL?

Read more

About the Author

Maria H. Underwood