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.
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?
- Because SQL columns point to related cells (data points), each key in a document also points to specific information (value).
- While SQL links tables in an object-to-relational mapping (ORM) system, NoSQL uses object document mapping (ODM) to link collections in a database.
- Data stored in NoSQL databases is readily available as unstructured JSON objects. SQL stores information in more organized data files.
- 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.
In the sidebar on the right, click To download to get the compatible version for your operating system.
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.
In the next window, copy the path of the file to the Data directory field and paste it somewhere you can edit it.
To replace The data in the path copied with trash can.
For example, if the path copied initially is:
Replace this with:
Once done, go back to the installation process and click on Following.
In the next step, select Complete to use the default installation.
Leave on Install the MongoDB compass box checked to install the GUI tool. Then click Following.
To select To install to install MongoDB server on your PC.
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.
In the next window, click on Environment variables.
Double click Path below 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.
Now open your terminal and type the following command:
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.
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 https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
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
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.
Choosing a database type can be tricky. Should you choose SQL or NoSQL?
About the Author