MongoDB注册为服务(命令行)

1、安装为服务

mongod --dbpath=D:\Database\MongoDB3\db --logpath=D:\Database\MongoDB3\log\mongo.log --port 27027 --noauth --install -serviceName MongoDB01 --serviceDisplayName MongoDB01

net start MongoDB01

mongo 127.0.0.1:27027/test

2、安装为服务,并开启用户认证

mongo 127.0.0.1:27027/admin

db.createUser({"user":"neo","pwd":"neo","customData":{"hobby":"tuzi"},"roles":["readWrite", "dbAdmin"]})

net stop MongoDB01

mongod --dbpath=D:\Database\MongoDB3\db --logpath=D:\Database\MongoDB3\log\mongo.log --port 27027 --auth --reinstall -serviceName MongoDB01S --serviceDisplayName MongoDB01S

net start MongoDB01S

mongo 127.0.0.1:27027/test -u neo -p neo

Leave a Reply

Your email address will not be published. Required fields are marked *

*