关于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?

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");

As described in the Connection String URI Format page, if the replicaSet option is omitted a standalone connection will be made. You'll want to use the replicaSet option to be able to connect to a new primary in the event of failover.