MongoDB\Driver\BulkWrite::__construct

(mongodb >=1.0.0)

MongoDB \ Driver \ BulkWrite :: __ 구성 - 새 BulkWrite 생성


설명

public MongoDB\Driver\BulkWrite::__construct(array $options = ?)

하나 이상의 쓰기 작업을 추가할 수 있는 변경 가능한 개체인 새 MongoDB\Driver\BulkWrite를 생성합니다. 그런 다음 쓰기는 MongoDB\Driver\Manager::executeBulkWrite()로 실행할 수 있습니다.


매개변수

options (array)

options

Option Type 설명 Default
bypassDocumentValidation bool true인 경우 문서 수준 유효성 검사를 우회하기 위해 삽입 및 업데이트 작업을 허용합니다.

이 옵션은 MongoDB 3.2 이상에서 사용할 수 있으며 문서 수준 유효성 검사를 지원하지 않는 이전 서버 버전에서는 무시됩니다.

false
ordered bool 순서가 지정된 작업(true)은 MongoDB 서버에서 직렬로 실행되는 반면, 순서가 없는 작업(false)은 임의의 순서로 서버로 전송되어 병렬로 실행될 수 있습니다. true

오류/예외


변경 로그

버전 설명
PECL mongodb 1.1.0 "bypassDocumentValidation" 옵션을 추가했습니다.

Examples

예제 #1 MongoDB\Driver\BulkWrite::__construct() 예제

                  
<?php

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

$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$writeConcern = new MongoDB\Driver\WriteConcern(1);

try {
    $result = $manager->executeBulkWrite('db.collection', $bulk, $writeConcern);
} catch (MongoDB\Driver\Exception\BulkWriteException $e) {
    $result = $e->getWriteResult();

    // Check if the write concern could not be fulfilled
    if ($writeConcernError = $result->getWriteConcernError()) {
        printf("%s (%d): %s\n",
            $writeConcernError->getMessage(),
            $writeConcernError->getCode(),
            var_export($writeConcernError->getInfo(), true)
        );
    }

    // Check if any write operations did not complete at all
    foreach ($result->getWriteErrors() as $writeError) {
        printf("Operation#%d: %s (%d)\n",
            $writeError->getIndex(),
            $writeError->getMessage(),
            $writeError->getCode()
        );
    }
} catch (MongoDB\Driver\Exception\Exception $e) {
    printf("Other error: %s\n", $e->getMessage());
    exit;
}

printf("Inserted %d document(s)\n", $result->getInsertedCount());
printf("Updated  %d document(s)\n", $result->getModifiedCount());
printf("Upserted %d document(s)\n", $result->getUpsertedCount());
printf("Deleted  %d document(s)\n", $result->getDeletedCount());

?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

Inserted 2 document(s)
Updated  1 document(s)
Upserted 1 document(s)
Deleted  1 document(s)
                

기타