0
我正在尋找正確的語法來使用replicaSet。我看到了PHP頁面http://php.net/manual/en/mongo.construct.php上的文檔,但我不太確定接下來會發生什麼。MongoDB PHP複製集正確的語法
<?php
// pass a comma-separated list of server names to the constructor
$m1 = new Mongo("mongodb://sf2.example.com,ny1.example.com", array("replicaSet" => "myReplSet"));
// you only need to pass a single seed, the driver will derive the full list and
// find the master from this seed
$m2 = new Mongo("mongodb://ny1.example.com", array("replicaSet" => "myReplSet"));
?>
在此之後,我應該寫類似
if($m1){ $mongo = $m1; }else{ $mongo = $m2; }
這是我用笨之內我現有的類的全部內容。需要將其切換爲支持副本集。
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class CI_Mongo extends Mongo
{
var $db;
function CI_Mongo()
{
// Fetch CodeIgniter instance
$ci = get_instance();
// Load Mongo configuration file
$ci->load->config('mongo');
// Fetch Mongo server and database configuration
$server = config_item('mongo_server');
$dbname = config_item('mongo_dbname');
// Initialise Mongo
if ($server)
{
parent::__construct($server);
}
else
{
parent::__construct();
}
$this->db = $this->$dbname;
}
}
?>
哇......完全誤讀該文檔:)謝謝! –
甚至會發生最好的;) –