(PECL mongoclient >=1.3.0)
PHP 和 MongoDB 之间的连接。
这个类用于创建和管理连接。典型的用法:
Example #1 MongoClient 基本用法
<?php
$m = new MongoClient(); // 连接
$db = $m->foo; // 获取名称为 "foo" 的数据库
?>
关于创建连接的更多信息,参见 MongoClient::__construct() 和 connecting 的章节。
NULL
;NULL
;$server
= "mongodb://localhost:27017"
[, array $options
= array("connect" => TRUE
)
]] )MongoClient::VERSION
MongoClient::DEFAULT_HOST
"localhost"
MongoClient::DEFAULT_PORT
27017
MongoClient::RP_PRIMARY
"primary"
MongoClient::RP_PRIMARY_PREFERRED
"primaryPreferred"
MongoClient::RP_SECONDARY
"secondary"
MongoClient::RP_SECONDARY_PREFERRED
"secondaryPreferred"
MongoClient::RP_NEAREST
"nearest"
TRUE
,否则是 FALSE
。
这个属性不考虑账户是否已认证。
NULL
。
mike at eastghost dot com (2013-03-07 09:35:54)
This will help maintain sanity while debugging replicaSet connectivity problems:
error_reporting( E_ALL )
// print every log message possible
\MongoLog::setLevel(\MongoLog::ALL); // all log levels
\MongoLog::setModule(\MongoLog::ALL); // all parts of the driver
mike at eastghost dot com (2013-03-07 09:34:24)
php monogo driver 1.3.4
feb 2013
After demoting old replicaset primary to secondary, and promoting old replicaset second into primary, we began seeing "No candidate servers found" MongoException at initial attempt to connect to (new) replicaset primary (via this hint in the /etc/mongo.conf: replSet = rs1/pri.eastghost.com)
Fix seems to be
1. NEVER list "localhost" in the bind= line of /etc/mongo.conf
2. ALWAYS list every replica set member in every member's /etc/hosts file -- there seems to be something wrong with DNS lookup timing.
jazz at funkynerd dot com (2012-11-28 01:36:46)
Seeing as the Mongo class has been deprecated, I'm using the following code to allow compatibility with the pre 1.3.0 driver successfully.
<?php
$class = 'MongoClient';
if(!class_exists($class)){
$class = 'Mongo';
}
$conn = new $class($hosts, $args);
?>