Install MongoDB as windows service

In this page I will show you how to install MongoDB in windows as service. Download MongoDB .msi file here and install. I assume that you install it in C:\Program Files\MongoDB. MongoDB will connect C:/data/db as default dbpath, if this directory doesn't exist you have to tell MongoDB the right dbpath. I create two directories for log(D:\mongo_data\log) and database(D:\mongo_data\db).

Start MongoDB Service

Before configuring MongoDB service you have to use following command to start MongoDB service.

复制代码
cd C:\Program Files\MongoDB\Server\3.0\bin
mongod.exe --dbpath D:\mongo_data\db

You will see the output like following

复制代码
2016-05-11T11:37:11.596+0800 I CONTROL  Hotfix KB2731284 or later update is not installed, will zero-out data files
2016-05-11T11:37:11.603+0800 I CONTROL  [initandlisten] MongoDB starting : pid=7188 port=27017 dbpath=D:\mongo_data\db 64-bit host=yong-PC
2016-05-11T11:37:11.603+0800 I CONTROL  [initandlisten] targetMinOS: Windows Server 2003 SP2
2016-05-11T11:37:11.603+0800 I CONTROL  [initandlisten] db version v3.0.10
2016-05-11T11:37:11.603+0800 I CONTROL  [initandlisten] git version: 1e0512f8453d103987f5fbfb87b71e9a131c2a60
2016-05-11T11:37:11.603+0800 I CONTROL  [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
2016-05-11T11:37:11.603+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2016-05-11T11:37:11.604+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "D:\mongo_data\db" } }
2016-05-11T11:37:11.613+0800 I JOURNAL  [initandlisten] journal dir=D:\mongo_data\db\journal
2016-05-11T11:37:11.614+0800 I JOURNAL  [initandlisten] recover : no journal files present, no recovery needed
2016-05-11T11:37:11.625+0800 I JOURNAL  [durability] Durability thread started
2016-05-11T11:37:11.626+0800 I JOURNAL  [journal writer] Journal writer thread started
2016-05-11T11:37:11.637+0800 I NETWORK  [initandlisten] waiting for connections on port 27017

You can press Ctrl + c to stop the service. As you can see it is a tedious process to start and stop the service. Next, I will show you how to configure MongoDB as windows service.

Configure MongoDB Service

Create a configuration file at C:\Program Files\MongoDB\Server\3.0\mongod.cfg like following.

复制代码
systemLog:
    destination: file
    path: D:\mongo_data\log\mongod.log
storage:
    dbPath: D:\mongo_data\db

Open windows command line and change directory to MongoDB installed and install MongoDB as windows Service

复制代码
cd C:\Program Files\MongoDB\Server\3.0\bin
mongod.exe --config "C:\Program Files\MongoDB\Server\3.0\mongod.cfg" --install

After executing the commands you can find MongoDB service in Windows Service Management(Win + R --> services.msc --> Enter)

You can create a shortcut to quick start and stop MongoDB service. How to create shortcut?

相关推荐
ClouGence37 分钟前
2026 年 4 款数据库管理工具推荐:免费、开源、付费怎么选?
数据库·后端·开源
SelectDB1 小时前
招联金融数仓升级:Apache Doris 统一 OLAP 引擎实现降本提效实践
数据库
SelectDB1 小时前
腾讯音乐内容库 ES 替代:从 Elasticsearch 到 Apache Doris 统一搜索分析引擎实践
数据库
SelectDB1 小时前
快手湖仓一体升级:从 ClickHouse 到 Apache Doris 的湖仓分离向湖仓一体演进实践
数据库
今天AI了吗1 小时前
深度学习基础-Harness:从评估框架到工程落地
数据库·人工智能·sql·深度学习·机器学习
一叶飘零_sweeeet1 小时前
别等业务中断才补坑!RTO/RPO 核心逻辑与全场景灾备架构选型全攻略
数据库·架构·容灾备份
码农颜2 小时前
6.1.2 常⽤⽅法的问题
数据库·sql·oracle
量子炒饭大师2 小时前
MySQL 5.7 在 CentOS 7 环境安装:从清理 MariaDB 到初始化与完善配置
数据库·mysql·centos·mariadb
易点云徐源2 小时前
(已解决)Photoshop 多画板 Alt+拖动复制随机卡死 4~5 分钟
windows·photoshop
明志数科2 小时前
宇树科技IPO背后的产业逻辑:人形机器人从“讲故事“到“交数据“
运维·服务器·数据库