dongping4461 2015-12-01 03:46
浏览 72
已采纳

关于mongo副本连接

In my test. use

$mongo = new MongoClient("mongodb://192.168.1.110:27017");

only take 1ms to connect the mongo PRIMARY.

But when I use

$mongo = new MongoClient("mongodb://192.168.1.110:27017,192.168.1.110:27018,192.168.1.110:27019/?replicaSet=test");

it will take 5ms. The cost is five times as long as the previous one.

How should I choose?

  • 写回答

2条回答 默认 最新

  • dongying3744 2016-02-08 03:07
    关注

    You should always be using your second option to connect replica set. Your first connection is connecting standalone server.

    What if machine or MongoDB instance fails in case of first option, you'll not be able to connect rest of nodes. Bottom line is always connect using 2nd suggestion. There will always be some penalty for added benefits, in this case fail safe availability.

    $mongo = new MongoClient("mongodb://192.168.1.110:27017,192.168.1.110:27018,192.168.1.110:27019/?replicaSet=test");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?