本文整理汇总了PHP中MongoCollection::insertMany方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCollection::insertMany方法的具体用法?PHP MongoCollection::insertMany怎么用?PHP MongoCollection::insertMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection::insertMany方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insert
public function insert($query, $force = false)
{
$this->items[] = $query;
$this->itemsCount++;
if ($this->itemsCount > 1000 or $force) {
$result = $this->collection->insertMany($this->items);
$this->itemsCount = 0;
$this->items = [];
return $result;
}
}
示例2: insert
/**
* Insert a new record into the database.
*
* @param array $values
* @return bool
*/
public function insert(array $values)
{
// Since every insert gets treated like a batch insert, we will have to detect
// if the user is inserting a single document or an array of documents.
$batch = true;
foreach ($values as $value) {
// As soon as we find a value that is not an array we assume the user is
// inserting a single document.
if (!is_array($value)) {
$batch = false;
break;
}
}
if (!$batch) {
$values = [$values];
}
// Batch insert
$result = $this->collection->insertMany($values);
return 1 == (int) $result->isAcknowledged();
}