1

How to create a database and user on mongodb without login the shell

I need to configure the MongoDB without entering into shell what is a method to configure the DB and user

Mongodb Add a comment
carter
asked Dec 04 2019
edited Dec 04 2019

Answer

1

Pre-requisites:

Create Admin User

Create a sample.js file

vim sample.js

Insert a db and user value

use sampledb

db.createUser({ user: "sampleusr", pwd: "xyz123", roles: [ { role: "readWrite", db: "sampledb" } ] })

Run the following command to create a DB and user without login the shell

mongo --username adminuser --password Passw0rd --authenticationDatabase admin --host 127.0.0.1 --port 27107 < sample.js
Add a comment
linuxhelp
asked Dec 04 2019
Post your Answer