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?

相关推荐
roman_日积跬步-终至千里几秒前
【数据Agent论文·查询与语义|06】RAT-SQL:怎样把问题、表和字段真正关联起来?
数据库·sql·数据分析
盟接之桥10 分钟前
盟接之桥谈线束数字化-按单入按单出:线束企业库存管理的破局之道
大数据·前端·网络·数据库·人工智能·制造
Nturmoils33 分钟前
数据集成软件 KFS:多套业务库汇聚时,先把来源和口径理清
数据库
钱栈up35 分钟前
耳机音效不对,我顺手查了系统更新,结果挖出个崩溃了整天的服务
windows·shell
麦壳饼41 分钟前
SonnetDB:批量写入的大小、背压与刷新策略
数据库·sonnetdb
xiao77mwq44 分钟前
Wireshark 在 Windows 上没法按进程抓包,我补了一条路
windows
weixin_460443561 小时前
Java+Linux私有化训考平台:服务、数据库与终端部署结构解析
java·linux·数据库·私有化部署·企业培训考试系统·企业考试系统
Helix2501 小时前
MDT自动化部署实战:构建企业级Windows批量装机与PXE网络引导环境
windows·mdt自动化部署·wds网络启动·pxe引导·windows批量装机·任务序列·无人值守安装
编程火箭车2 小时前
MySQL 拥抱 AI:向量、RAG、AutoML 全进了数据库
数据库·mysql·ai编程·向量数据库·rag·automl·mysql9
用户8662978480082 小时前
KingbaseES 中文乱码、排序不对?区域和字符集的问题,一次说清
数据库