PHP Conference Japan 2024

MongoDB\Driver\WriteResult::getUpsertedCount

(mongodb >=1.0.0)

MongoDB\Driver\WriteResult::getUpsertedCount傳回透過更新插入操作插入的文件數量

說明

final public MongoDB\Driver\WriteResult::getUpsertedCount(): ?int

參數

此函式沒有參數。

傳回值

傳回透過更新插入操作插入的文件數量。

錯誤/例外

範例

範例 #1 MongoDB\Driver\WriteResult::getUpsertedCount() 範例

<?php

$manager
= new MongoDB\Driver\Manager;

$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['x' => 1]);
$bulk->update(['x' => 1], ['$set' => ['y' => 3]]);
$bulk->update(['x' => 2], ['$set' => ['y' => 1]], ['upsert' => true]);
$bulk->update(['x' => 3], ['$set' => ['y' => 2]], ['upsert' => true]);
$bulk->delete(['x' => 1]);

$result = $manager->executeBulkWrite('db.collection', $bulk);

var_dump($result->getUpsertedCount());

?>

上述範例將輸出

int(2)

另請參閱

新增註記

使用者提供的註記

此頁面沒有使用者提供的註記。
To Top