【问题标题】:MongoDB replicaSet pymongo connectionMongoDB 副本集 pymongo 连接
【发布时间】:2012-12-04 10:05:50
【问题描述】:

我有三个 mongod 节点,添加到副本集(例如 localhost:27001,27002,27003)。 如果应用程序不知道哪个节点是主节点,如何从 pymongo 连接到它?

【问题讨论】:

    标签: mongodb pymongo


    【解决方案1】:

    您只需要提供每个副本,驱动程序就会为您选择主副本。在此处查看文档:

    pymongo Conneting to Replica Set

    具体

    >>> Connection("mongodb://morton.local:27017,morton.local:27018,morton.local:27019")
    Connection(['morton.local:27019', 'morton.local:27017', 'morton.local:27018'])
    

    【讨论】:

    • 如果这有帮助,请考虑投票/接受答案。
    猜你喜欢
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 2013-05-25
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    相关资源
    最近更新 更多