Setting up MongoDB with Sitecore and MongoDB UI
Posted 08/01/2016 by sanjeev gupta
I was struggling to setup MongoDB with sitecore on my development machine. It took some time for me to sort out all the issues. I thought why not I should share all the steps with other sitecore developers.
The following resources are required for a functional MongoDB setup:
- Create a local Sitecore 8.1 Instance.
- Verify Sitecore connection strings.
<?xml version="1.0" encoding="utf-8"?>
Sitecore connection strings.
All database connections for Sitecore are configured here.
<add name="analytics" connectionString="mongodb://localhost/analytics" />
<add name="tracking.live" connectionString="mongodb://localhost/tracking_live" />
<add name="tracking.history" connectionString="mongodb://localhost/tracking_history" />
- Download MongoDB from https://www.mongodb.com/download-center
Here's a step-by-step guide to getting the MongoDB to work once you have all of the resources.
Standard setup instructions
- Ensure you have installed and configured your Sitecore Instance.
- Install MongoDB using the Custom installation so you can change the default location. Typically, I put all my projects and websites on a separate non-operating system drive such as a D: drive. I will prefer to install mongo to D:/MongoDB/. Before you start the custom installation please complete Step 3/4 & 5.
- In the folder “MongoDB” create a folder called “data” and inside that folder, create a folder called “db”. Inside “data” folder, create another folder “log”. These will not be created for you during install so you will need to create them before MongoDB installation.
- In the folder “MongoDB” create another folder called “config” and inside config folder, create a new .cfg file and name it “mongod.cfg”. This is where we will store the configurations for MongoDB.
- Copy/paste following the configuration into the new “mongod.cfg” file and modify to your specific workstation:
- Now, install MongoDB as a Windows Service, so it will start every time you start up Windows and stay running. Open up a Command Prompt (Run As Administrator) and type in the following (modify if needed for your file paths):
D:\mongodb\bin\mongod.exe --dbpath "c:\mongodb\data\db"
sc.exe create MongoDB binPath= "D:\mongodb\bin\mongod.exe --service --config=\"D:\mongodb\config\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
- This will create a new windows service called MongoDB. Now, to start the service simply type in the following: net start MongoDB
MongoDB's UI tools
You only need to setup the MongoDB admin UI if you want to verify that your data is being stored. There are several MongoDB Admin UI tools out there, some are free and some are paid. You can use GUI tools like MongoVUE or RoboMongo to work with Mongo data. After trying both, I will prefer RoboMongo as open source MongoDB management tool (i.e. Admin GUI).
You can download Robomongo from their website. Setup is a very easy. The UI gives you the ability to connect to different Mongo instances.
Once connected, you can use the UI to traverse through the collections and the data stored in them. Additionally you can also run db commands against the collections and display results in three different formats (hierarchy, table view and text view). Apart from the features mentioned it has the ability to perform all admin tasks such as clearing data, get db statistics, repair/drop db, insert/update/delete records, etc.