You can easily migrate from a standalone server to a MongoDB Atlas cluster. MongoDB Atlas is the fully managed service for MongoDB deployments in the cloud. To learn more, see Migrate or Import Data in the MongoDB Atlas documentation.
To install a standalone instance, see the installation tutorials.
When possible, use a logical DNS hostname instead of an ip address, particularly when configuring replica set members or sharded cluster members. The use of logical DNS hostnames avoids configuration changes due to ip address changes.
Restart the instance. Use the
--replSetoption to specify the name of the new replica set.
For example, the following command starts a standalone instance as a member of a new replica set named
rs0. The command uses the standalone's existing database path of
mongod --port 27017 --dbpath /srv/mongodb/db0 --replSet rs0 --bind_ip localhost,<hostname(s)|ip address(es)>
If your application connects to more than one replica set, each set must have a distinct name. Some drivers group replica set connections by replica set name.
rs.initiate()to initiate the new replica set: