
MongoDB의 BulkWrite API에서 updateOne 메서드와 update 메서드는 모두 여러 문서를 업데이트할 수 있는 메서드입니다.
차이점은 updateOne 메서드는 첫 번째 조건에 해당하는 문서 하나만 업데이트하는 반면, update 메서드는 첫 번째 조건에 해당하는 문서를 업데이트하고, 이후에 조건에 해당하는 문서를 업데이트합니다.
update 메서드는 여러 문서를 업데이트할 수 있지만, updateOne 메서드는 첫 번째 조건에 해당하는 문서 하나만 업데이트합니다. BulkWrite API에서 update 메서드를 사용하면 여러 문서를 업데이트할 수 있습니다.
예를 들어, 다음과 같은 BulkWrite API를 사용할 수 있습니다.
#hostingforum.kr
php
$bulk = $collection->bulkWrite([
[
'updateOne' => [
'filter' => ['name' => 'John'],
'update' => ['$set' => ['age' => 30]],
],
],
[
'updateOne' => [
'filter' => ['name' => 'Jane'],
'update' => ['$set' => ['age' => 25]],
],
],
]);
이 예제에서는 updateOne 메서드를 사용하여 두 명의 사람의 나이를 업데이트합니다. BulkWrite API에서 update 메서드를 사용할 수 있습니다.
#hostingforum.kr
php
$bulk = $collection->bulkWrite([
[
'update' => [
'$set' => ['age' => 30],
],
'filter' => ['name' => 'John'],
],
[
'update' => [
'$set' => ['age' => 25],
],
'filter' => ['name' => 'Jane'],
],
]);
이 예제에서는 update 메서드를 사용하여 두 명의 사람의 나이를 업데이트합니다. BulkWrite API에서 updateOne 메서드와 update 메서드는 모두 사용할 수 있습니다.
2025-06-17 00:40