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:
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: