使用PHP Mongo连接哪个Mongo服务器?

时间:2012-08-22 07:21:17

标签: php mongodb

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

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

谢谢!

1 个答案:

答案 0 :(得分:2)

如果您有sharded environment,则应运行一个或多个mongos服务器(通常每个应用程序服务器一个),而不是直接连接到副本集。

摘自the MongoDB documentation

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.

mongosmongod服务器的connection应该与连接到<?php $m = new Mongo("mongodb://mymongos1:27017"); ?> 服务器的服务器相同,例如:

{{1}}