Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有三个 mongod 节点,添加到副本集(例如 localhost:27001,27002,27003)。如果应用程序不知道哪个节点是主节点,如何从 pymongo 连接到它?
您只需提供每个副本,驱动程序将为您选择主副本。请参阅此处的文档:
pymongo 连接到副本集
具体来说
>>> Connection("mongodb://morton.local:27017,morton.local:27018,morton.local:27019") Connection(['morton.local:27019', 'morton.local:27017', 'morton.local:27018'])