Great question. To convert from standalone to replica set, the preferred procedure is to:
- Shut down the standalone mongod instance.
- Change its config to include the option
replication.replSetName, with the name of your new replica set. - Connect to the instance, and run the command
rs.initiate(). This will initiate the replica set, and your standalone will now be the primary node. - Start some other mongod instances (at least two).
- Add the other instances to your replica set with
rs.add(). (You must run this command from the primary node.)
To your second question, if your database is sufficiently large, you should use mongodump or mongoexport to export the data from your primary, and then send the data to your secondary nodes. Then you can import them to your secondary nodes with mongorestore or mongoimport, depending on whether you used mongodump or mongoexport.
You can find more detail on the docs. I hope this helps!
Matt