Changing data directory for MongoDB in Sitecore

As part of my MongoDB Blog series part 1, we discussed how we can Install MongoDB and we used “C” drive as default Installation location for it.

But as a best practice and considering scalable environment, we shouldn’t be using “C” drive to store any application data, it should be reserved only for system files, so that if we need to upgrade the OS or need to repair existing Installation, our application data is still safe.

We have done this for one of the implementation, and it’s always better to do this in early phase of the development.

We can always go back and change the default data directory location for MongoDB in Sitecore, and can use mongo config file which we created for Installing MongoDB.(Please refer MongoDB Blog series part-1 for more details)

This is how it was before:

mongoconfig

Let’s use another drive to store data and logs for MongoDB, in this case it’s “G

mongoconfigrevised

From the above screenshot we can see that, the data and log folder points to “G” drive now, and rest of the configuration is all same.

If you Installed MongoDB as a service, your service still points to “C” drive, but your data and log will be stored in “G” drive.

If you want to copy over existing data from “C” to “G” (in this example), make sure to stop your service, copy your data from “C” to “G”(in this example) and restart MongoDB Service.

This is good from maintenance perspective, and easy to manage afterwards.

I hope this helps someone, who is looking for something similar.

Thanks, and please let me know for any questions and any feedback, happy to discuss more.

Happy learning 🙂

Advertisements

Sitecore MongoDB Blog series: Part 1-Introduction to MongoDB in Sitecore

Sitecore introduced MongoDB in it’s ecosystem to solve the problem of scaling analytics, let’s try to understand MongoDB from Sitecore prespective, and see how it’s useful and where exactly it sit in the Sitecore system, we will have series of three posts where we will start with the introduction about it, it’s features, advantages, setting up MongoDB in your environment.

In the second series we will talk about contacts and some of the out of the box queries, and will to understand MongoDB collection, and in the final post we will see how we can create custom facets to extend MongoDB functionality.

mongodb

Introduction to MongoDB

Sitecore 7.5 introduced MongoDB as the main datastore for the Sitecore Experience Database (xDB). Sitecore xDB allows organizations to collect all of their customer interactions from all channels to create a comprehensive, single view of the customer that allows marketers to better optimize the customer experience in real-time.

Following are some of the features of MongoDB:

  • Open source
  • NoSQL
  • Document oriented database.
  • Primarily used for collecting data and information about visitors(for analytics)
  • Visitors and their interactions are written to MongoDB in JSON format, which then processed by an aggregation pipeline into a format that is used for reporting.

There are several advantages and benefits with MongoDB, some of them are listed below:

  • Scalability
    • Standalone environment
    • Vertical Scaling and
    • Horizontal Scaling
  • Performance
  • Flexibility
  • Unstructured data and Schemas

Scaling is one of the critical feature in Sitecore, and we will discuss about all different scaling options in the next series of this post, where we will talk more about horizontal scaling and how MongoDB uses it to make sure the availability of data.

Installing MongoDB:

Let’s take a look, how you can install MongoDB:

Please follow the below steps, to install MongoDB.

  1. Download MongoDB as per your Sitecore version, you can see more details here: https://doc.sitecore.net/sitecore_experience_platform/setting_up_and_maintaining/xdb/platform/software_recommendations and
  2. https://kb.sitecore.net/articles/633863
  3. Next, you need to install Mongo, you can do it either in default installation path (C:\Program Files\MongoDB\Server\mongo version), or in custom path like (D:\Mongo\..)
  4. Create data and db folder:
    1. C:\Program Files\MongoDB\Server\3.0\data
    2. This folder is not created by default during installation, we need to install this.
    3. Once this folder is create, please create db folder under this.
  5. Create logs folder:
    1. C:\Program Files\MongoDB\Server\3.0\logs
  6. We can create a new config file where we specify db and logs folder, and this file will be used to install MongoDB as a service, so that it will start everytime when we start/boot windows.
  7. In this example, I have created a new folder “config” and added config file under that.
  8. C:\Program Files\MongoDB\Server\3.0\config
  9. Please use the below snippet and save make sure to change the db and log location, as per your environment location.mongoconfig
  10. C:\Program Files\MongoDB\Server\3.0\config\mongod-3.0.cfg
  11. Open up a Command Prompt (Run As Administrator), and navigate to bin folder
    1. C:\Program Files\MongoDB\Server\3.0\bin
  12. Run the following command to create MongoDB as a service:
  13. mongod –config=”C:\Program Files\MongoDB\Server\3.0\config\mongod-3.0.cfg” –install –serviceName=”MongoDB 3.0″
  14. Go to services and look for “MongoDB 3.0”, click startMongoDBService

Connection Strings:

mongo_connectionstring

  • name – analytics,tracking.live, tracking.history and tracking.contact.
  • mongodb prefix
  • servername- in case of local, it’s default to localhost
  • Mongo database(collection name)

Note:

This is for replicate set

mongo_connectionstring_replicaset

This is how contact looks in Mongo, and some out of the box properties.

contactcard

Hope this helps to give you base level understanding about MongoDB in Sitecore, and how to install MongoDB as windows service.

In the next post, we will see how we can scale MongoDB in Sitecore, and also closer look of contacts,collection and some queries to get data out of it.

Let me know your comments and feedback on the same, and anything which want to me cover specifically.

References:

https://briancaos.wordpress.com/2014/10/01/sitecore-and-xdb-setting-up-mongodb-on-your-developer-machine/

Happy learning 🙂