https://www.mongodb.com/download-center#community
网站下载mongodb 安装(自定义安装,去掉对号–Install Mongodb Compass)
4.2.3
首先在服务器的D盘下面创建1个文件夹(前提有D:\log)
D:\data\db
然后进入到mongodb的bin目录下,根据安装路径,我这里是 D:\mongodb\bin
先打开一个命令行窗口执行如下语句
mongod.exe --dbpath D:\mongodb\data\db
会出现一行显示 waiting for connections on port 27017,表示启动成功,先不要关闭窗口
在当前目录下再开一个cmd窗口执行命令
mongo.exe
会显示mongodb的版本号就表示没问题
配置服务并设置远程连接
接下来我们要配置mongodb的服务,让服务器成为一台mongodb服务器
这一步,如果你能在你的mongodb目录中找到mongod.cfg,就可以直接修改bindIp,否则在mongodb的bin目录下创建一个文本文件,并且命名为 mongod.cfg,注意缩进要用4个空格
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: D:\mongodb\data
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: D:\mongodb\log\mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
#processManagement:
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
#mp:
然后以管理员身份在bin目录下执行如下命令,使配置生效
mongod.exe --config "D:\mongodb\bin\mongod.cfg" --install
这样就可以使用命令管理mongodb并且开机启动
接下来两个命令很重要,要都执行
关闭mongodb net stop mongodb
开启mongodb net start mongodb
设置了0.0.0.0允许远程访问
参考博客https://blog.csdn.net/qq_40456064/article/details/90405156