I did MongoDB installation why new databases are reason to agitation to me! I love to instal and to do very crazy tests, remove, install again…
With MongoDB was not different! I installed and I wanted to do a first test… But not did’n work! I removed… I install again.
Until I read the error message in start of MongoDB service (mongod.exe) and it said that the it was not finding the data directory. OMG…Read the error message saves time this, my first tip. Just kidding !
MongoDB
MongoDB (from Humongous) is the most used NoSQL database in the world! Its a open source database, is possible use it on commodity hardware and in multiple platform, is possible horizontally scaling (increase database performance adding more nodes in a cluster), and is a document oriented database.
MongoDB doesn’t store data in table format, the data in MongoDB is semistructured.
It receives JSON (Java Script Object Notation) documents and convert it to BSON (Binary JASON) format and store it in this format.
Here I need to say that MongoDB isn’t perfect to all situations! This is perfect to store semistructured data!
Is important to say that MongoDB is schemeless. But what does that mean? The documents stored in the database can have varying sets of fields, with different types for each field.
Turning or not a mess depends on governance, but the fact is that a change in the MongoDB’s structure tends to be much faster .
Download
To install MongoDB make a download in oficial web site.
Why use the community version? Simple because is free and is enough to learn 🙂
But Dani you said that MongoDB is open source… Yes I said! But Enterprise version has other services and is proper to use in data center and is paid version.
Ok… Make the download according your operational system. I used stable version, but is possible use previous release (if you don’t have reason, don’t do this) ou development version (if you like challenges).
MongoDB Installation
Is very simple, make a download and use the installer. I used the installer in Mac and in Windows too and are very similar.
See the pictures above:
The installation process is basically the popular “Next -> Next -> Next”!!! Very easy!
Data directory, the first thing that you should know…
Before start to first time, MongoDB service is necessary manually create data directory. This was reason to my first tentative didn’t work!
The data directory must be in the root volume of installation. For example, if you installed in C:\MongoDB, the data directory will be inside C:\.
By default you need to create a data directory and inside it create the directory db. In our exemple the data directory is C:\data\db.
Is important have full permission in this directory.
The dbpath parameter – The second thing
If you want to use other folder to be data directory is possible! But when you start mongod by command line is necessary to use –dbpath parameter.
Exemple: > C:\MongoDB\bin\mongod.exe —dbpath C:\MongoDB\NovoDiretorioDados
The configuration file – The third thing
If you don’t want to use the default data directory, don’t want to use dbpath parameter there is a third option, use a configuration file and inside it specify the data directory.
This file has YAML format and can contains all options used in command line. If you want to know all option, see MongoDB official site (https://docs.mongodb.com/manual/reference/configuration-options/)
To use configuration file in command line there are two options:
> C:\MongoDB\bin\mongod.exe -f C:\MongoDB\mongod.conf
> C:\MongoDB\bin\mongod.exe –config C:\MongoDB\mongod.conf
Conclusion
- To install MongoDB make a download in oficial site;
- The community version is free;
- The installation is Next -> Next -> Next;
- Is necessary create a data directory;
- The default path to data directory is Volume\data\db;
- Is possible to use other paths to data directory, but in the mongod execution by command line is necessary to use the parameter — dbpath with the new data directory path.
- Is possible use the configuration file, and in this specify the data directory. To use this option in mongod command use the parameter -f or –config.
Next steps
We begin today a article series talking about MongoDB. The next ones we will talk about are:
- MongoDB architecture
- Queries:
- Inclusion,
- Exclusion,
- Update,
- Data query.
- Write Concern;
- Replication;
- Sharding
References
The official MongoDB website is always a good idea!
If you liked it, share this post! If you have questions, talk to me.