Introduction
The following instructions are for the latest version of MongoDB (2.6.12) on the Linux server of choice (CentOs 7 64-bit). CentOs is just the free version of Redhat and offers all the features minus the corporate support. Coming from a Windows development background, this entry is a little off the main course of my usual tips and tech posts but will be useful nonetheless since Mongo is traditionally hosted in the Linux environment. Traditional Microsoft stack applications are starting to have LAMP pieces added to the mix. Besides, in a production environment, all of this is license free even if the Microsoft pieces are not.
Steps
- sudo -i
This will get you in administrator mode to remove all restrictions moving forward.
- nano /etc/yum.repos.d/mongodb.repo
This opens the yum repo file in the NANO editor, which has an easy-to-understand "interface".
- Paste in (for 64-bit servers, different for 32-bit)
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
This stores the location of the install file to prepare for the YUM package manager to download and install.
- Save, exit nano
- yum install mongo-10gen mongo-10gen-server
At this point the mongo service is installed and ready to use
- service mongod start
This starts the service.
service mongod stop
This stops the service.
service mongod restart
You will need to restart the service if configuration items are changed. The configuration file is here:
/etc/mongod.conf
- To autostart:
chkconfig mongod on
Management
The Mongo installation on the server comes with a web user interface assuming the server has the Apache web server installed which most likely it does. The web UI can be accessed here from within the same machine:
http://localhost:28017
To access remotely, you would need to perform some systems administration on the firewall to open up the IP address to the public along with both ports 27017 and 28017 (direct connection and web connection default ports). The web UI would then be accessed here:
http://IPADDRESS:28017
The web UI is nothing more than just a status and health page. It is a good indicator that Mongo is up and running as well as provide setup and status metrics but nothing more. To view collections and documents, I recommend standalone apps such as RoboMongo. To connect directly to the database, you would need to provide the host and port number at the very minimum. Again. if Robomongo is installed locally then the host would be localhost and port is 27017 and IP address if connecting remotely. The ports as well as other configuration data points can be changed via the configuration file.
Comparison of Data Storage
There is a wealth of information on the Internet to obtain information on adding databases and collections. A collection can be compared to a table in a relational database. An item in a collection is a document and can be compared to a data record in a relational database. A main difference between a document and a data record is that data records all have the same fields. Documents in the same collection do not have to have the same fields. They are just JSON objects that can have different fields and structures. Since they are JSON objects, they could also have nested fields such as an address object within a user profile object. In the relational database model, the address data records would be in a separate table and related to the user record via an address id number. A big advantage of NoSQL over RDBMS is that there are less queries and JOINS required to obtain the same information. In the address example only one "SELECT" query is needed for Mongo vs a SELECT and a JOIN in MSSQL. A big drawback of Mongo in having nested objects is that indexing them becomes more complex in search platforms such as SOLR since search engines traditionally expect flat objects coming in to be indexed. The resulting indexed documents can be multi-dimensional but that's from data transformation during the indexing process and not directly from the incoming objects.
Security
Upon setup of Mongo, there are no users and roles created and only local access is permitted. This means that the web UI and the direction connections can only be accessed on that machine even if a login is not required. In the event that the firewall is opened to allow for remote connections then security has to be added to prevent free-for-all access to your database. The easiest way to do this is to create new users assigned to the database. By adding just one user, security is turned on system-wide. At this point the web UI will prompt you for a user name and password in order to access. There was no indication of this in the Mongo documentation. None of the users that you added to your custom database is accepted on this login screen. Those users are only for direct connections when reading or writing to that database. To enable access to the web UI, you would need to create a user in the "admin" database.
Search
Search queries can be performed directly in Mongo via JSON request objects. This is sufficient for most scenarios. Mongo scales horizontally so you can always add more servers to the farm for more storage and processing power as well as load balancing and redundancy. There are also justifications for an external search mechanism instead of using Mongo and to have Mongo used solely as a data store. It is simple enough to connect search platforms such as Apache SOLR to index documents and collections from a Mongo database. There is no out-of-the-box support for this but there are solutions to be found on the Internet via custom solutions.
Conclusion
MongoDB is an nifty data storage solution. It is free, scales horizontally, which is more flexible than vertical scaling, and can be set up in a very short amount of time. The community and the support from fellow developers is top notch. Although there are drawbacks compared to a traditional relational database but the advantages of performance and simpler query structures far outweigh those disadvantages.
Nice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best. Mongo Database Services
ReplyDeleteHow to Solve MongoDB Installation Issue on CentOS through DB Installation Support
ReplyDeleteIf you are not able to install MongoDB on your CentOS or confronting any type of technical issue regarding any database then you can contact to DB Configuration Support and DB Installation and Configuration Support. We quickly detect issues that might threaten its performance or security. We always alert you if any critical issues have been occurred.
For More Info: https://cognegicsystems.com/
Contact Number: 1-800-450-8670
Email Address- info@cognegicsystems.com
Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801