Setting up Replication

Hi @Master_Selcuk ,

Replica sets are designed for high availability and. failover, so each replica set member includes the same set of data (with the exception of the local system database, which is used for instance-specific data like the replication oplog). In a failover/election scenario, you want to have multiple members of a replica set eligible to become primary so there is some fault tolerance allowing some members of your replica set to be temporarily unavailable while still maintaining a primary.

If you only want to copy a subset of collections or databases, you will have to work out a separate solution from the built-in replication. For example, you could have multiple MongoDB deployments and Back up & Restore selected databases with MongoDB tools. You could also implement custom sync in application code using Change Streams to follow and relay data changes of interest.

You can use any available port on your local server:

  • Ports 1024-49151 (“registered ports”) are used for applications. Popular applications often have registered standard ports to avoid conflicts for default installations. The default MongoDB ports are 27017-27020. You generally want to avoid using a port commonly used by another service (for example, MySQL’s default port is 3306) but the main technical limitation is that you can’t have two different processes listening to the same IP:port combination.

  • Ports 0-1023 (“welll-known ports”) are usually used for system services (DNS, SSH, LDAP, …) and typically require superuser access (so are not recommended for applications like MongoDB).

  • Ports 49152-65535 are typically used for dynamic or ephemeral ports.

Your replica set members will need to be able to communicate with each other via the configured IP:port combinations, so you will have to set up appropriate firewall and networking configuration. The MongoDB Security Checklist has more information on recommended security measures.

Regards,
Stennie

5 Likes