라이브러리
[PHP] MongoDBDriverBulkWrite::update - 대량 업데이트 작업 추가
MongoDBDriverBulkWrite::update
`MongoDBDriverBulkWrite::update` 메소드는 MongoDB 데이터베이스의 문서를 업데이트하는 BulkWrite 연산을 수행합니다. 이 메소드는 `$set`, `$unset`, `$push`, `$pull`, `$pullAll`, `$inc`, `$mul`, `$rename`, `$currentDate`, `$min`, `$max`, `$addToSet`, `$pop`, `$bit`, `$type` 등의 업데이트를 지원합니다.
사용법
`MongoDBDriverBulkWrite::update` 메소드는 다음과 같은 형식으로 사용할 수 있습니다.
#hostingforum.kr
php
$bulkWrite = new MongoDBDriverBulkWrite;
$bulkWrite->update($filter, $update, $options);
- `$filter`: 업데이트할 문서를 찾기 위한 필터입니다.
- `$update`: 업데이트할 문서의 내용입니다.
- `$options`: 업데이트에 대한 옵션입니다.
예제
다음 예제는 `$set` 업데이트를 사용하여 이름을 업데이트하는 방법을 보여줍니다.
#hostingforum.kr
php
$manager = new MongoDBDriverManager('mongodb://localhost:27017');
$bulkWrite = new MongoDBDriverBulkWrite;
$filter = ['_id' => new MongoDBBSONObjectId('...')];
$update = ['$set' => ['name' => 'John Doe']];
$options = ['upsert' => true];
$bulkWrite->update($filter, $update, $options);
$writeConcern = new MongoDBDriverWriteConcern(MongoDBDriverWriteConcern::MAJORITY, 1000);
$result = $manager->executeBulkWrite('database.collection', $bulkWrite, $writeConcern);
if ($result->getInsertedCount() > 0) {
echo "업데이트 성공
";
} else {
echo "업데이트 실패
";
}
옵션
`$options` 배열에는 다음과 같은 옵션을 사용할 수 있습니다.
- `upsert`: 업데이트할 문서가 없을 때 새로운 문서를 삽입할지 여부입니다. 기본값은 `false`입니다.
- `multi`: 여러 문서를 업데이트할지 여부입니다. 기본값은 `false`입니다.
- `arrayFilters`: `$in`, `$nin`, `$ne`, `$eq`, `$gt`, `$lt`, `$gte`, `$lte`, `$mod`, `$and`, `$or`, `$not` 등의 필터를 사용할 수 있습니다.
- `bypassDocumentValidation`: 문서의 유효성을 검사하지 않고 업데이트할지 여부입니다. 기본값은 `false`입니다.
- `ordered`: BulkWrite 연산을 순서대로 수행할지 여부입니다. 기본값은 `true`입니다.
참고
- MongoDB Driver의 [BulkWrite](https://www.php.net/manual/kr/mongodb-driver-bulkwrite.php) 문서를 참조하세요.
- MongoDB Driver의 [UpdateOne](https://www.php.net/manual/kr/mongodb-driver-bulkwrite.updateone.php) 메소드를 참조하세요.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.