How to change name of replica set

I need to change my replica name and I tried using these commands:

use local  
var doc = db.system.replset.findOne()  
doc._id = 'NewReplicaSetName'
db.system.replset.save(doc)  
db.system.replset.remove({_id:'OldReplicaSetName'})

Unluckily, I got such error:
(…) not authorized on local to execute command { update: “system.replset” (…)

even though I used this command to log into mongo:
mongo --port 27011 --username m103-admin --password m103-pass --authenticationDatabase admin

Do you know how to solve this issue?
Or do you know different way to change name of replica set?

Please have a read:
https://docs.mongodb.com/manual/faq/replica-sets/#can-i-rename-a-replica-set

In this instance, you need to create a new replica set with the correct name.

1 Like

This does not work. When I want to drop database I have the following error: (…) not authorized on local to execute command (…) even though I logged into db with admin credentials.

Share a screenshot of the connection string and a screenshot of the drop command + error.

mongo --host "localhost:27011" -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin"
MongoDB shell version v3.6.17



MongoDB Enterprise m103-example:PRIMARY> db.dropDatabase()
{
        "operationTime" : Timestamp(1582623596, 1),
        "ok" : 0,
        "errmsg" : "not authorized on local to execute command { dropDatabase: 1.0, lsid: { id: UUID(\"09fa18e9-896d-4335-9daa-043f28c13f95\") }, $clusterTime: { clusterTime: Timestamp(1582623596, 1), signature: { hash: BinData(0, 357847A7CA9E17AFD922816AC0D3D4B985A565C2), keyId: 6797067491479650328 } }, $db: \"local\" }",
        "code" : 13,
        "codeName" : "Unauthorized",
        "$gleStats" : {
                "lastOpTime" : Timestamp(0, 0),
                "electionId" : ObjectId("7fffffff0000000000000008")
        },
        "$configServerState" : {
                "opTime" : {
                        "ts" : Timestamp(1582623594, 1),
                        "t" : NumberLong(2)
                }
        },
        "$clusterTime" : {
                "clusterTime" : Timestamp(1582623596, 1),
                "signature" : {
                        "hash" : BinData(0,"NXhHp8qeF6/ZIoFqwNPUuYWlZcI="),
                        "keyId" : NumberLong("6797067491479650328")
                }
        }
}

The local database is a system database. But why do you want to drop any database anyway? Maybe you’re thinking about db.shutdownServer()? Remember to switch to the admin db first.

No.
I want to change name of Replica Set. In link that you sent me I found this: https://docs.mongodb.com/manual/tutorial/restore-replica-set-from-backup/

One of the steps is to drop local database.

As part of the “dropping the local db” step, it actually says:


… which means, shutdown the node, start it up using the mongod command and --dbpath option that’s pointing to the datafile, then delete the local db. No other options should be used in the connection string.

However, those steps are for production. The simpler non-production steps that’s relevant for this course is the one I mentioned in my first post:

… did you try this instead?

1 Like

No, I didn’t. I’m not sure how to do this. I just started mongods with diffrent replSetName but it just directed me to another error so I didn’t try that way as I though I have to remove the previous Replica Set at first.

So let’s understand your setup.

  1. Did you already add this replica set as a sharded cluster in the mongos?
  2. What is the title of the lab or lecture you’re working on?
  1. Yes, I think so.
  2. Lab - Configure a Sharded Cluster

Sorry I am completely lost. I manged to launch mongos with config servers and replica set but the validation script said that name of the replica has to be m103-repl and now I don’t know how to change it. (my old one was m103-example)

Ok, because you’ve got one shard, here’s what to do:

  1. Find all the mongod and mongos processes
    ps -ef | grep [m]ongo
  2. Kill all the relevant mongos and mongod (data replica set and config replica set) processes using the pid (process id):
    kill pid
  3. Delete all the data files. The command below will delete the files, not the directories.:
    rm -r /var/mongodb/db/{1,2,3,csrs1,csrs2,csrs3}/*
  4. Alter the replica set name in the config files and start to build up your replica sets and mongos again.
2 Likes

Hi @Agnieszka_Morzywolek_63138,

Please follow the instructions shared by @007_jb in the previous post.

Rebuild the m103-repl replica set and the m103-csrs replica set and you should be good to go from here.

If you face any difficulty then please feel free to get back to us.

Thanks,
Shubham Ranjan
Curriculum Services Engineer

Thank you. It worked :smile:

No problem Aga :smile:

Closing this thread as the issue has been resolved.