The dbpath is where all of the DBs are stored right, so if I am setting up the primary node for example it would write and read the data to the specified DBs from the dbpath and then would forward the data to the Secondary nodes for replication. In the Secondary nodes, the replicated data forwarded from the Primary node will be stored in the dbpath as well a reading of the dataset will be made from it by the client application.
That is correct, the purpose of the --dbPath is to tell MongoDB where you want it to store the data on disk. If you don’t provide the flag MongoDB will use a default path but this let’s you choose where you want to store your data on disk.
In a replica set the primary and secondary’s will hold all of the data (just in case it become primary or you want to read from secondary). Each one has their own dbPath that you specify.
If you are trying to understand replication, then you may have 3 instances running in the same machine (3 is the suggested minimum), then dbpath along with port becomes clearer.
by creating 3 data folders such as data1, data2 and data3 and starting on 3 different ports such as 27001, 27002 and 27003, this local replica set (after other commands to complete replication) will just be as ready as any remote replica sets.
It is not that simple. If you have existing data, then you can copy it but then you will need to go through a set of operations so that other servers can work with that data.
After you have set your replica set, either locally or remote, the primary will communicate with the secondaries @Doug_Duncan wrote above.