1. Mongodb without authentication
C:\\mongodb\\bin C:\\mongodb\\data
C:\mongodb\bin\mongod.exe --dbpath "C:\mongodb\data"
or
C:\mongodb\bin\mongod.exe --dbpath="C:\mongodb\data"
Default port is 27017
2. Enable authentication
First we need to start mongoDB without authentication
C:\mongodb\bin\mongod.exe --dbpath "C:\mongodb\data"
After that run following commands :
1. Run mongo client with : mongo.exe
2. Use data base with : use admin
3. Add user and role : db.createUser({"user":"root","pwd":"123456","roles":[{"role":"readWriteAnyDatabase","db":"admin"},{"role":"userAdminAnyDatabase","db":"admin"},{"role":"dbAdminAnyDatabase","db":"admin"}]})
The object of root user(for easy to read)
db.createUser({ "user":"root", "pwd":"123456", "roles":[ { "role":"readWriteAnyDatabase", "db":"admin" }, { "role":"userAdminAnyDatabase", "db":"admin" }, { "role":"dbAdminAnyDatabase", "db":"admin" } ] });
And start with authentication mode:
#mongod.exe --dbpath="C:\mongodb\data" --auth
3. Creating window service with configuration file
mongo.cfg placed in c:\mongodb\etc\
systemLog: destination: file path: c:\\mongodb\\etc\\mongodb.log logAppend: true storage: dbPath: c:\\mongodb\\data journal: enabled: true processManagement: windowsService: serviceName: t2i-mongodb-server displayName: T2i mongoDb server display name. description: The service for MongoDatabase security: authorization: enabled net: bindIp: 127.0.0.1 port: 27017
Command to start as service
"C:\mongodb\bin\mongod.exe" --config "C:\mongodb\etc\mongo.cfg" --install
No comments:
Post a Comment