本文整理汇总了PHP中MongoCollection::setWriteConcern方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCollection::setWriteConcern方法的具体用法?PHP MongoCollection::setWriteConcern怎么用?PHP MongoCollection::setWriteConcern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection::setWriteConcern方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setWriteConcern
/**
* Define write concern for all requests to current collection
*
* @param string|integer $w write concern
* @param int $timeout timeout in milliseconds
* @throws \Sokil\Mongo\Exception
* @return \Sokil\Mongo\Collection
*/
public function setWriteConcern($w, $timeout = 10000)
{
if (!$this->_mongoCollection->setWriteConcern($w, (int) $timeout)) {
throw new Exception('Error setting write concern');
}
return $this;
}
示例2: __construct
/**
* Constructor
*
* @param Mongo|MongoClient|array|Traversable $mongo
* @param string|MongoDB $database
* @param string $collection
* @param array $saveOptions
* @throws Exception\InvalidArgumentException
*/
public function __construct($mongo, $database = null, $collection = null, array $saveOptions = array())
{
if ($mongo instanceof Traversable) {
// Configuration may be multi-dimensional due to save options
$mongo = ArrayUtils::iteratorToArray($mongo);
}
if (is_array($mongo)) {
$saveOptions = isset($mongo['save_options']) ? $mongo['save_options'] : array();
$collection = isset($mongo['collection']) ? $mongo['collection'] : null;
$database = isset($mongo['database']) ? $mongo['database'] : null;
$mongo = isset($mongo['mongo']) ? $mongo['mongo'] : null;
}
if (null === $collection) {
throw new Exception\InvalidArgumentException('The collection parameter cannot be empty');
}
if (null === $database) {
throw new Exception\InvalidArgumentException('The database parameter cannot be empty');
}
if (!($mongo instanceof MongoClient || $mongo instanceof Mongo)) {
throw new Exception\InvalidArgumentException(sprintf('Parameter of type %s is invalid; must be MongoClient or Mongo', is_object($mongo) ? get_class($mongo) : gettype($mongo)));
}
$this->mongoCollection = $mongo->selectCollection($database, $collection);
// Set write concern
$this->mongoCollection->setWriteConcern(0);
$this->saveOptions = $saveOptions;
}