2012-08-22 37 views

回答

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. 

connectionmongos服務器(S)應指定一樣的,你會連接到服務器mongod,如:

<?php 

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

?> 
+0

嗯。感謝Stennie!該文檔沒有詳細說明如何使用客戶端連接到mongos。 –

+1

@ Salocin.TEN:正確..我向Jira問題跟蹤器添加了一個文檔建議:[https://jira.mongodb.org/browse/PHP-460](https://jira.mongodb.org/browse/ PHP-460)。 – Stennie

+0

我猜測它沒有被添加,因爲嘗試執行某些findOne()調用時拋出了一些套接字異常。 –