password protected mongo server 1

password protected mongo server

db.createUser({ user: "admin", pwd: "adminpassword", roles: [{ role: "userAdminAnyDatabase", db: "admin" }] })

Here is what the above code is Doing:
1. Connect to the MongoDB server
2. Create a new database called “mydatabase”
3. Create a new collection called “customers”
4. Insert a document into the “customers” collection
5. Create a new user called “admin” with the password “adminpassword”
6. Give the “admin” user the role of “userAdminAnyDatabase”

Similar Posts