{"id":133,"date":"2025-07-02T19:33:39","date_gmt":"2025-07-02T19:33:39","guid":{"rendered":"https:\/\/blog.hostek.com\/?p=133"},"modified":"2025-07-02T19:33:39","modified_gmt":"2025-07-02T19:33:39","slug":"how-to-setup-secure-and-scale-mongodb-on-windows-server","status":"publish","type":"post","link":"https:\/\/hassantest-com.server-hassanzahoor-com.vps.ezhostingserver.co.uk\/blog\/how-to-setup-secure-and-scale-mongodb-on-windows-server\/","title":{"rendered":"How to setup, secure and scale MongoDB on Windows Server"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Downloading an installer, and running a through the setup are the most common steps for a basic installation. Even for database systems. But for learning something new, that might end up in production, it\u2019s important to consider how to setup, secure and scale the platform \u2013 in this case MongoDB.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Last week we published a guide on <a href=\"https:\/\/hassantest-com.server-hassanzahoor-com.vps.ezhostingserver.co.uk\/blog\/everything-you-need-to-run-node-js-applications-on-windows-iis\/\">installing Node.js on Windows and using iisnode<\/a> to facilitate connections through IIS. Making the same assumption, that as an organization you\u2019re committed to Microsoft Server products this article is for you.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For this example I\u2019ll use our Windows VPS server platform. I suggest the Silver <a href=\"https:\/\/hostek.com\/hosting\/windows\/vps\/windows-vps-hosting\">Windows VPS<\/a> Plan if you want to try these steps out for yourself. Some requirements might include the need for a separate instance to for mongoDB exclusively. <a href=\"https:\/\/help.hostek.com\/en\/\">We can talk<\/a> about that toward the end \u2013 under scaling mongoDB.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing mongoDB on Windows<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We will install mongoDB as a service in Windows so we can control the user it runs as, easily restart it, or set recovery parameters. Download the latest release.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Be sure the version matches your platform. There\u2019s already excellent \u201cHow to install MongoDB on Windows\u201d instructions at the mongoDB website so here\u2019s <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/tutorial\/install-mongodb-on-windows\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">the link<\/a>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The initial instructions don\u2019t cover installing it as a service, so skip ahead about 1\/2 way down to the title: <strong>Configure a Windows Service for MongoDB<\/strong><\/li>\n\n\n\n<li>Also the instructions mention installing at c:\\mongodb, during installation you will need to customize the path to match their examples.<\/li>\n\n\n\n<li>You might opt to change the data directory for db and logs as well. To keep things tidy I decided to create it in the root folder for mongoDB: <strong>c:\\mongodb\\data<\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Production Specific Settings:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I strongly encourage anyone to review the production related notes. Quickly scanning through them there are some changes to the pagefile and tcp keep alive time. Although if you\u2019re not planning for a heavy or mission critical load this can probably be left alone. I did set the keep alive time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One particular setting regarding Windows Virtual machines is modifying the keepalive time, which you can do quickly with this one command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>reg add HKLM\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\ \/v KeepAliveTime \/d 0x0124c0<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Service Adjustments<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We recommend adjusting the service recovery to restart on failure. That way if something goes wrong Windows can attempt to restart the mongoDB service without your help. You can do this by opening services, properties, changing the failure actions to \u201crestart\u201d.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Security<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MongoDB by default runs without requiring authentication. This is quite different from the traditional relational database installation defaults. MongoDB documents are very explicit about this, and describe that mongoDB is by default for use in \u201cTRUSTED\u201d environments. Meaning, with secured ports or only accessible on local networks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These are also areas that should be explored, for more security:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/core\/security-mongodb-configuration\/#http-interface-security\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Disabling HTTP Interface<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/tutorial\/configure-ssl\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Using SSL\/TLS between servers<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mongodb.com\/solutions\/industries\/healthcare\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">HIPPA Compliance<\/a> \u2013 which you may not need, but this is an excellent read on maximizing mongoDB security<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Scaling mongoDB (optional):<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are also many ways to scale your mongoDB setup. The first is by performance gains through additional RAM, storage etc. The \u201chardware\u201d specs, that can easily be changed. These are covered in the production related notes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Second is through creating a <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/replication\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Master\/Slave replication<\/a>. Which seems very similar to MySQL Master\/Slave setup except mongoDB seems to handle the initial sync process nicely.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There\u2019s also <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/tutorial\/deploy-replica-set\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Replica Sets<\/a> and <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/sharding\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Sharding<\/a>. These are beyond the scope of setting up a new mongoDB installation but as needs grow, these are well documented solutions that don\u2019t cost a penny \u2013 just take time and in some cases lots of servers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing your installation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you\u2019ve got mongo running, you can test your installation from the command line by running: <strong>mongo<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Overall mongoDB is impressive, easy to install but should be treated as any other database system, carefully and with thought.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Downloading an installer, and running a through the setup are the most common steps for a basic installation. Even for database systems. But for learning something&hellip;<\/p>\n","protected":false},"author":2,"featured_media":135,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[13,14,15],"class_list":["post-133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-vps","tag-vps-hosting","tag-windows-vps"],"_links":{"self":[{"href":"https:\/\/hassantest-com.server-hassanzahoor-com.vps.ezhostingserver.co.uk\/blog\/wp-json\/wp\/v2\/posts\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hassantest-com.server-hassanzahoor-com.vps.ezhostingserver.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hassantest-com.server-hassanzahoor-com.vps.ezhostingserver.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hassantest-com.server-hassanzahoor-com.vps.ezhostingserver.co.uk\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hassantest-com.server-hassanzahoor-com.vps.ezhostingserver.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":0,"href":"https:\/\/hassantest-com.server-hassanzahoor-com.vps.ezhostingserver.co.uk\/blog\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hassantest-com.server-hassanzahoor-com.vps.ezhostingserver.co.uk\/blog\/wp-json\/wp\/v2\/media\/135"}],"wp:attachment":[{"href":"https:\/\/hassantest-com.server-hassanzahoor-com.vps.ezhostingserver.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hassantest-com.server-hassanzahoor-com.vps.ezhostingserver.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hassantest-com.server-hassanzahoor-com.vps.ezhostingserver.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}