Answer for MongoDB 5.0 release.
The initial sync may take some time - be patient. As far as I see it runs in two steps. First MongoDB clones all collections, i.e. it makes a "plain" copy of all collections. You can monitor this by connecting to syncing member and run rs.status().initialSyncStatus.databases
shard_03:STARTUP2> rs.status().initialSyncStatus.databases
{
"failedInitialSyncAttempts" : 0,
"maxFailedInitialSyncAttempts" : 10,
"initialSyncStart" : ISODate("2022-04-28T08:33:36.519Z"),
"totalInitialSyncElapsedMillis" : 6548240,
"initialSyncAttempts" : [ ],
"approxTotalDataSize" : NumberLong("488957278026"),
"approxTotalBytesCopied" : NumberLong("519033102224"),
"remainingInitialSyncEstimatedMillis" : -379443,
"appliedOps" : 0,
"initialSyncOplogStart" : Timestamp(1651134817, 16004),
"totalTimeUnreachableMillis" : NumberLong(0),
"databases" : {
"databasesToClone" : 2,
"databasesCloned" : 5,
...
"plau01mipmed0" : {
"collections" : 9,
"clonedCollections" : 8,
"start" : ISODate("2022-04-28T09:56:10.907Z"),
"plau01mipmed0.sessions" : {
"documentsToCopy" : 16449103,
"documentsCopied" : 16891103,
"indexes" : 4,
"fetchedBatches" : 242,
"bytesToCopy" : NumberLong("3816816827"),
"approxBytesCopied" : NumberLong("3918735896"),
"start" : ISODate("2022-04-28T09:56:10.907Z"),
"end" : ISODate("2022-04-28T09:59:02.068Z"),
"elapsedMillis" : 171161,
"receivedBatches" : 242
},
"plau01mipmed0.ignored" : {
"documentsToCopy" : 8095615,
"documentsCopied" : 5711111,
"indexes" : 2,
"fetchedBatches" : 86,
"bytesToCopy" : 1966181814,
"approxBytesCopied" : 1382088862,
"start" : ISODate("2022-04-28T10:22:17.332Z"),
"receivedBatches" : 86
}
After some time you should get result like
shard_03:STARTUP2> rs.status().initialSyncStatus.databases
...
{
...
"databases" : {
"databasesToClone" : 0,
"databasesCloned" : 7
}
}
After that MongoDB starts to apply the oplog. You can monitor it with this command:
shard_03:STARTUP2> rs.status().members.filter(x => x.name == db.hello().me).forEach(
x => printjson(
{
date: ISODate(),
name: x.name,
stateStr: x.stateStr,
optimeDate: x.optimeDate,
oplog_BacklogSeconds: (ISODate() - x.optimeDate) / 1000
}
)
)
{
"date" : ISODate("2022-04-28T11:27:42.111Z"),
"name" : "d-mipmdb-sh2-03:27018",
"stateStr" : "STARTUP2",
"optimeDate" : ISODate("2022-04-28T09:40:50Z"),
"oplog_BacklogSeconds" : 6412.111
}
Again, you need to be patient. oplog_BacklogSeconds
should slowly decrease. Sooner or later, the member state should go to SECONDARY
. As this time the sync is not fully done, i.e. oplog_BacklogSeconds
may still show a high number, but it should decrease rather fast. When it becomes 1-2 Seconds then it is fully done.