Search code examples
mongodbadminfsync

db.fsyncLock() without permission in MongoDB (auth enabled)


i have added auth to my MongoDB instance. I created a user with the following command

db.createUser(
 { user: "cocodrile", pwd: "amazonas",
   roles: [
       { role: "userAdminAnyDatabase", db: "admin"},
       { role: "dbOwner", db: "admin"},         
       { role: "dbOwner", db: "brasil_database"}, 
       { role: "dbOwner", db: "usa_database"} ,
       { role: "dbOwner", db: "argentina_database"},
       { role: "dbOwner", db: "test"}] })

I want to perform a db.fsyncLock() and it says:

db.fsyncLock()
{
    "ok" : 0,
    "errmsg" : "not authorized on admin to execute command { fsync: 1.0, lock: true }",
    "code" : 13
}

What i am doing wrong? Thanks!


Solution

  • You're missing the hostManager built-in role, which has permissions to monitor and manage servers and perform some cluster-as-a-whole actions like fsync.