Download sample MongoDB configuration file
In previous post Installing MongoDB for MVC applications, I discussed the very first step of installing MongoDB database in your environment. In production environment you are not going to be using your database as a console application with whatever default settings it is shipped with. For production environment you want control on various run time options. MongoDB documents have lot of details on this topic. In this post I will highlight topics that may or may not be very clear in the documentation. In this post I will focus on following topics.
In previous post I mentioned that when you try to execute Mongod.exe from command line without any parameters, it complains that there is no data folder specified. Then I specified that value using dbpath option on command line. In production environment you are going to have a lot of configuration parameters. It is not going to be practical to specify all those parameters on command line. MongoDB allows you to specify all these parameters in a configuration file. This configuration is nothing but a text file and you can put all your configuration values in that file on separate lines. You can get all the details of this configuration file from Run-time Database Configuration page in MongoDB documentation. Following link on MongoDB web site provides all the parameters that you can configure for your database.
For this docussion I will focus on very basic options that you will need to get your database configured for most situations.
I have attached sample MongoDB configuration file with thise post that I have used for my prototype development.
Like any other database, you would want that your database starts running when machine starts. And definitely it will be preferable that database is running as a background process and not a console application. MongoDB can be configured as a windows service.
Install MongoDB on Windows page in documentation at the bottom specifies steps to follow to run MongoDB as Windows service. This is where the configuration file that we created is going to come handy. Following command installs MongodB as service.
mongod.exe --config C:\mongodb\mongod.cfg --installConfig command line parameter allows you to specify location of configuration file.
Important:It is very important that command line shell is running under administrator account when you install the service. Windows needs elevated privileges to install a windows service. If you do not run as administrator then installation will throw an error with error telling that access is denied.
When you execute above command, windows will pop a dialog box telling you that MongoD is making changes to your system configuration. It will ask for permission. Go ahead and click on "Allow" button to proceed with installation. Now you will see an entry for MongoDB in your services list.
As you can see from above screenshot, now you can finish service configuration. Change service Startup type to Automatic if you want MongoDB to start when operating system starts. This interface will allow you to configure account that should be used to run MongoDB service. By default it will use Local System Account. I will recommend that you create a new windows user account with controlled rights and then configure MongoDB to use that account. This is good security practice.
Now your MongoDB is configured as windows service. You can start the service either from command line using net start mongod command or from user interface by clicking on Start button.
Now that we have MongoDB all up and running for prime time operations, in next post I will show some basic operations we can perform from our MVC application.
Error when adding service reference for WCF service
How to plan CCSP Exam preparation
Develop a MongoDB pipeline to transform data into time buckets
Alert and Confirm pop up using BootBox in AngularJS
AngularJS Grouped Bar Chart and Line Chart using D3
How to lock and unlock account in Asp.Net Identity provider
2024 © Byteblocks, ALL Rights Reserved. Privacy Policy | Terms of Use