Can't migrate standalone MongoDB to Cluster
-
18-02-2021 - |
Question
I'm trying to convert a standalone MongoDB database into a cluster in order to migrate my database to MongoDB Atlas.
I've followed the following steps to try and convert it:
- Stop my mongodb instance
- Changed the configuration to the following content:
........................
#how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
security:
authorization: enabled
replication:
replSetName: "rs0"
- Restarted mongodb with the following command:
sudo mongod --config /etc/mongod.conf --fork
- Logged into mongodb, to the admin database, with a user who has the following roles:
clusterMonitor, readAnyDatabase, userAdminAnyDatabase
- Executed the command
rs.initiate()
And it gave me the following error:
{
“ok” : 0,
“errmsg” : “not authorized on admin to execute command { replSetInitiate: undefined, $db: \“admin\” }“,
“code” : 13,
“codeName” : “Unauthorized”
}
I have tried the previous steps in a dev server, and everything worked fine, bun in my production environment it didn't work, any help is appreciated.
Solution
Logged into mongodb, to the admin database, with a user who has the following roles:
clusterMonitor
,readAnyDatabase
,userAdminAnyDatabase
...
not authorized on admin to execute command { replSetInitiate: undefined, $db: \“admin\” }“
This error is expected since clusterMonitor
is a read-only role.
To initialise or update replica set configurations when access control is enabled your user needs a cluster management role like clusterManager
or clusterAdmin
.