By Ran Bar-Zik | 1/23/2018 | General |Beginners

Intro to MongoDB - Installing your working environment

Intro to MongoDB - Installing your working environment

MongoDB is a non-relational database that uses a non-tabular method of data storage, aka NoSQL (not only SQL). With it, we can present data on web pages and application, just like when using MySQL.

 

The question often arises as to why we need to use MongoDB. Why not just stay with MySQL or another relational database? There are a few good answers to this, with the first being that with MongoDB there are no JOINS and it therefore performs better. It is also much easier to scale projects with MongoDB than with SQL. There are also several other advantages with regards to specific applications.

 

I could continue to go on about why you should use MongoDB, but if you’re already here, then you probably have a good reason to be using it—be it for work or just to learn the new technology. Research and Development managers that need to make a decision about which type of database to use in their projects won’t come here to decide. For these reasons I won’t expand upon the ‘which is better’ debate, especially since there isn’t one clear answer. What is clear though, is that MongoDB is far better than SQL for solving certain types of problems. Further MongoDB is probably the most popular NoSQL database out there for web development, so it’s a pretty good idea to learn it, even if you’re planning on moving on to a different NoSQL sch as Cassandra.

 

So let’s start—first with what we need to know before jumping in. MongoDB works with the syntax of JSON and JavaScript. This doesn’t mean that you need to be an expert front-end developer to use it, but if you haven’t written any JavaScript since the 80’s then it might be a good time to brush up a bit—especially when it comes to working with objects in JavaScript. Also, you should already has some knowledge of relational databases. While it’s true that MongoDB works in a completely different way, it would be good to already be familiar with some sort of database methodology.

 

It’s easy to install MongoDB whether you’re in a Unix based system or in Windows. I’m a Linux type of guy and my work environment is Linux so the example I’ll give here will be in Linux. But it’s really easy to install MongoDB in Windows too.

 

Let’s get started with installation. In reality, the documentation provided by MongoDB is quite good for Linux, Windows and Mac, but if you on Linux and feelin’ lazy, just run these commands:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

sudo apt-get update

sudo apt-get install -y mongodb-org

Once you’ve run the commands on your computer, you can just type mongo and you should be up and running.

 

In Windows, just download the files mongo.exe and mongod.exe, open the command prompt, and run mongod.exe then mongo.exe to get started. That’s it!

 

When working with MongoDB we’ll do so via its console, just like in MySQL. After we’ve opened the console, we can start to work with the database. Just how there are databases in MySQL, the same holds true for MongoDB. Each database stands alone and a good rule of thumb is to have one database for one project. (At least at the beginning.)

 

In order to view all of the database we have in MongoDB, run the following command:

show dbs

This command will show us all of the databases. If you’ve just installed MongoDB, you’ll see:

admin  (empty)
local  0.078GB

In order to create and start working with a database, we’ll need to use it. That may sound confusing but you see, in MongoDB, we don’t just simply create a database, but rather they are created when we start to populate them. So how do we use MongoDB databases? And how do we input data? All this we’ll cover in the next article on collections.

Next article: Collections in MongoDB


About the author:
Ran Bar-Zik is an experienced web developer whose personal blog, Internet Israel, features articles and guides on Node.js, MongoDB, Git, SASS, jQuery, HTML 5, MySQL, and more. Translation of the original article by Aaron Raizen.

By Ran Bar-Zik | 1/23/2018 | General

{{CommentsModel.TotalCount}} Comments

Your Comment

{{CommentsModel.Message}}

Recent Stories

Top DiscoverSDK Experts

User photo
3355
Ashton Torrence
Web and Windows developer
GUI | Web and 11 more
View Profile
User photo
3220
Mendy Bennett
Experienced with Ad network & Ad servers.
Mobile | Ad Networks and 1 more
View Profile
User photo
3060
Karen Fitzgerald
7 years in Cross-Platform development.
Mobile | Cross Platform Frameworks
View Profile
Show All
X

Compare Products

Select up to three two products to compare by clicking on the compare icon () of each product.

{{compareToolModel.Error}}

Now comparing:

{{product.ProductName | createSubstring:25}} X
Compare Now