1

我有 3 个副本集,每个副本集在自己的分片中。每个副本集有 2 个 Mongo 服务器(主服务器和从服务器)。

使用 Mongo() 的连接字符串时,我应该连接到哪个服务器?

谢谢!

4

1 回答 1

2

如果您有一个分片环境,您应该运行一台或多mongos台服务器(通常每个应用程序服务器一台),而不是直接连接到副本集。

MongoDB 文档的摘录:

The mongos process can be thought of as a routing and coordination process
that makes the various components of the cluster look like a single system.
When receiving client requests, the mongos process routes the request to the
appropriate server(s) and merges any results to be sent back to the client.

与服务器的连接mongos应指定为与连接mongod服务器相同,例如:

<?php

    $m = new Mongo("mongodb://mymongos1:27017");

?>
于 2012-08-22T07:31:16.563 回答