MongoDB 单机与副本集以及如何将数据从单机迁移到副本集

MongoDB standalone vs replica set and how to migrate data from a standalone to a replica set

我有几个关于 MongoDB 独立和副本集的问题,我不太明白。

我之所以问所有这些问题,是因为最近我正在尝试实施交易,而会话只能在 "replica sets" 开始,我根本不明白其中的区别。

  • 我应该什么时候使用它们?

Replication is the process of synchronizing data across multiple servers. Replication provides redundancy and increases data availability with multiple copies of data on different database servers. Replication protects a database from the loss of a single server. Replication also allows you to recover from hardware failure and service interruptions. With additional copies of the data, you can dedicate one to disaster recovery, reporting, or backup.

  • To keep your data safe
  • High (24*7) availability of data
  • Disaster recovery
  • No downtime for maintenance (like backups, index rebuilds, compaction) Read scaling (extra copies to read from)
  • Replica set is transparent to the application
  • 为什么所有的副本集教程都显示3个连接,有什么原因吗?

The basic implementation to take full advantage of replication specifies you should have at least one primary node with two secondary nodes. So the examples are always with 3 nodes. Not only this if from 3 the Primary node goes down you still have 2 nodes (mongoDB will assign using arbiter rule) and one primary and one secondary for high availability

  • 我可以只为 1 个实例创建副本集吗?在那种情况下,它与独立 mongodb 实例有何不同?

It does not make sense to have single instance with mongo replication.

  • 如何将数据从独立实例迁移到副本集?

Convert a Standalone to a Replica Set . Your existing data will be migrated to all replication instances once they are up and running when converted to replication sets from standalone.