viernes, 17 de enero de 2025

mongodb initialization

 

  1. Start MongoDB without access control.

     mongod --port 27017 --dbpath /data/db1
    
  2. Connect to the instance.

     mongosh --port 27017
    
  3. Create the user administrator.

     use admin
     db.createUser(
       {
         user: "myUserAdmin",
         pwd: passwordPrompt(), // or cleartext password
         roles: [ 
           { role: "userAdminAnyDatabase", db: "admin" },
           { role: "readWriteAnyDatabase", db: "admin" } 
         ]
       }
     )
    
  4. Re-start the MongoDB instance with access control.

     mongod --auth --port 27017 --dbpath /data/db1
    
  5. Authenticate as the user administrator.

     mongosh --port 27017 --authenticationDatabase "admin"\
         -u "myUserAdmin" -p 
    

No hay comentarios:

Publicar un comentario