Compact oplog.rs

Hi everyone,

i’m facing some issues with oplog size, we are trying to compact it, as shown in other topics (Mongodb Atlas compact oplog.rs) , but it seems we can’t do it because of our privileges.

So, we are trying to create a custom role with compact action in local database but we don’t have enough privileges either to create a role with compact privilege in local database.

We are trying to do these actions with a user with dbadmin privileges, but it is impossible. Any ideas??

Thanks in advance

Hello @Jose_Cristino_Fernandez ,

Welcome to The MongoDB Community Forums! :wave:

Is your deployment local or Atlas?
If Atlas then, what deployment you are using? M0,M2…M10 etc?

Note: Serverless instances don’t support Oplog feature at this time. To learn more, see Serverless Instance Limitations.

If you are using local environment then please explain, why are you trying to compact the oplog? The oplog is constantly being written to at a rate of every 10 seconds in an idle replica set (see https://jira.mongodb.org/browse/SERVER-23892), so there’s little to no benefit in compacting it.
However to directly answer your question, you need to use a user with dbadmin privileges., had dbadmin privileges?
To check this, you can run the db.getUser() command to retrieve information about the user. For example, if the username is “myuser”, you can run the following command:

db.getUser("myuser")

Examine the roles field in the output to see if the user has been granted the dbAdmin role. For example, the output might look like this:

{
    "_id" : "mydb.myuser",
    "user" : "myuser",
    "db" : "mydb",
    "roles" : [
        {
            "role" : "dbAdmin",
            "db" : "mydb"
        }
    ],
    "mechanisms" : [
        "SCRAM-SHA-1"
    ]
}

In this example, the user “myuser” has been granted the dbAdmin role on the mydb database. If the roles field does not contain the dbAdmin role, the user does not have that role.

Please refer to below documentation to learn more about compact command and required privileges.

Note: Always have an up-to-date backup before performing server maintenance such as the compact operation.

Lastly, you can also take at below threads which is related to your query

Regards,
Tarun