Collection [local.oplog.rs] not found issue when restarting mongod for setting up replica set

2.2k Views Asked by At

I have followed the official documentation for converting the standalone mongodb instance (local ubuntu machine) to replica set. The part where we restart mongod with --replset flag seems to invite an error.

Command used:

sudo systemctl stop mongod

sudo mongod --port 27017 --dbpath /var/lib/mongodb --replSet rs1 --bind_ip localhost

{"t":{"$date":"2023-11-24T17:58:28.002+05:30"},"s":"W",  "c":"QUERY",    "id":23799,   "ctx":"ftdc","msg":"Aggregate command executor error","attr":{"error":{"code":26,"codeName":"NamespaceNotFound","errmsg":"Unable to retrieve storageStats in $collStats stage :: caused by :: Collection [local.oplog.rs] not found."},"stats":{},"cmd":{"aggregate":"oplog.rs","cursor":{},"pipeline":[{"$collStats":{"storageStats":{"waitForLock":false,"numericOnly":true}}}],"$db":"local"}}}

The cmd goes into a loop printing this message again and again, till I force close the program.

I have tried reinstalling mongodb to see if it is a random issue. But it prevails nevertheless.

Tried multiple variations of the mongod restart command. Used different shutdown procedures.

1

There are 1 best solutions below

1
Mike Miller On

I had the same problem when trying to connect with Compass.

But I was able to run mongosh on the server's shell, and then run rs.initiate() from there.

Once rs.initiate() was finished, I am able to connect with Compass to all of the nodes in the replication set and verify replication is working.