Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MongoDB 3.6.0 2008R2Plus SSL (64 bit) installed and running as service at start-up.
- Config file is at C:\Program Files\MongoDB\Server\3.6\mongod.cfg and contains
- systemLog:
- destination: file
- path: D:\MongoDB\log\mongod.log
- storage:
- dbPath: D:\MongoDB\db
- security:
- authorization: enabled
- Data directory at D:\MongoDB\db and logs at D:\MongoDB\log
- Admin user
- user: mongoAdmin
- pass:
- db.grantRolesToUser("mongoAdmin",["root"])
- To login to mongo from cmd line:
- mongo --port 27017 -u "mongoAdmin" -p "" --authentionDatabase "admin"
- To run the script to create databases and associated accounts for new users:
- mongo createMongo.js --port 27017 -u "mongoAdmin" -p "" --authentionDatabase "admin"
- createMongo.js:
- var users = [student nums or similar here];
- var curDB;
- for(var i = 0; i < users.length; i++) {
- curDB = db.getSiblingDB(users[i]);
- curDB.exampleCollection.save( {test: "testValue"} );
- curDB = db.getSiblingDB("admin");
- curDB.createUser(
- {
- user: users[i],
- pwd: users[i],
- roles: [ { role: "readWrite", db: users[i] } ]
- }
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement