Sync Problem After first initiate()

I created config flie for 3 node. I initiated replicaiton set and tried to add nodes. I checked the status but sync host is different for all nodes. Node1: Primary has no sync host. That’s fine. Node2:Secondary sync to Node1, Node3:Secondary sync to Node2.
Afterwards I have ran the rs.stepDown() command 2 times. then I got status as below.
Why cannot I get this status after first initiate ?

MongoDB Enterprise m103-repl:PRIMARY> rs.status()
{
        "set" : "m103-repl",
        "date" : ISODate("2019-12-11T05:21:07.837Z"),
        "myState" : 1,
        "term" : NumberLong(3),
        "syncingTo" : "",
        "syncSourceHost" : "",
        "syncSourceId" : -1,
        "heartbeatIntervalMillis" : NumberLong(2000),
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(1576041659, 1),
                        "t" : NumberLong(3)
                },
                "readConcernMajorityOpTime" : {
                        "ts" : Timestamp(1576041659, 1),
                        "t" : NumberLong(3)
                },
                "appliedOpTime" : {
                        "ts" : Timestamp(1576041659, 1),
                        "t" : NumberLong(3)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1576041659, 1),
                        "t" : NumberLong(3)
                }
        },
        "members" : [
                {
                        "_id" : 0,
                        "name" : "192.168.103.100:27001",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 353,
                        "optime" : {
                                "ts" : Timestamp(1576041659, 1),
                                "t" : NumberLong(3)
                        },
                        "optimeDate" : ISODate("2019-12-11T05:20:59Z"),
                        "syncingTo" : "",
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "",
                        "electionTime" : Timestamp(1576041658, 1),
                        "electionDate" : ISODate("2019-12-11T05:20:58Z"),
                        "configVersion" : 3,
                        "self" : true,
                        "lastHeartbeatMessage" : ""
                },
                {
                        "_id" : 1,
                        "name" : "192.168.103.100:27002",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 211,
                        "optime" : {
                                "ts" : Timestamp(1576041659, 1),
                                "t" : NumberLong(3)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1576041659, 1),
                                "t" : NumberLong(3)
                        },
                        "optimeDate" : ISODate("2019-12-11T05:20:59Z"),
                        "optimeDurableDate" : ISODate("2019-12-11T05:20:59Z"),
                        "lastHeartbeat" : ISODate("2019-12-11T05:21:06.405Z"),
                        "lastHeartbeatRecv" : ISODate("2019-12-11T05:21:07.364Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncingTo" : "192.168.103.100:27001",
                        "syncSourceHost" : "192.168.103.100:27001",
                        "syncSourceId" : 0,
                        "infoMessage" : "",
                        "configVersion" : 3
                },
                {
                        "_id" : 2,
                        "name" : "192.168.103.100:27003",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 209,
                        "optime" : {
                                "ts" : Timestamp(1576041659, 1),
                                "t" : NumberLong(3)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1576041659, 1),
                                "t" : NumberLong(3)
                        },
                        "optimeDate" : ISODate("2019-12-11T05:20:59Z"),
                        "optimeDurableDate" : ISODate("2019-12-11T05:20:59Z"),
                        "lastHeartbeat" : ISODate("2019-12-11T05:21:06.404Z"),
                        "lastHeartbeatRecv" : ISODate("2019-12-11T05:21:07.804Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncingTo" : "192.168.103.100:27001",
                        "syncSourceHost" : "192.168.103.100:27001",
                        "syncSourceId" : 0,
                        "infoMessage" : "",
                        "configVersion" : 3
                }
        ],
        "ok" : 1
}
MongoDB Enterprise m103-repl:PRIMARY>

@Beytullah_48478 please edit your post and enclose the code in quotes so that it retains the indents for easy reading. Here’s how (using the backtick character) exactly like this:
image

Or you can use the pre html tag.

This is not a problem. It’s handled internally.

The syncingTo field is no longer in use. You can use syncSourceHost and syncSourceId instead.

If there’s no activity, it may not show up immediately. Next time, insert 1 document into a test collection and check rs.status() again and the two sync fields should be filled.

Hi @Beytullah_48478,

I don’t think you should be concerned about the sync source for your secondary until or unless you have a reason to do so, such as you are running a production cluster or something.

That being said, I know its fun to know more about things that you are learning so let’s see what’s happening here :slightly_smiling_face: .

In MongoDB replica sets, we have the concepts of chaining. When this is enabled then the Secondary nodes can select any other Secondary node as its sync source. And by default this is set to true. And that’s why Node 3 was syncing from the Node 2 when you first initiated the replica set. Your sync source can change from time to time based on some factors.

This whole process of selecting the sync source is taken care of by MongoDB. You do not need to worry about it. That being said, if you want to change it then you can do so by using the rs.syncFrom() command.

Hope it helps!

If you still have any questions then please feel free to get back to us.

Thanks,
Shubham Ranjan
Curriculum Support Engineer

Thanks a lot Shubham.