팁
MongoDB는 대량 쓰기 작업을 수행하기 위한 Mongo.bulkWrite() 메서드도 제공합니다.
설명
Bulk.find.updateOne(<update>)단일 문서 업데이트 작업을 대량 작업 목록에 추가합니다.
Use the
Bulk.find()method to specify the condition that determines which document to update. TheBulk.find.updateOne()method limits the update to a single document. To update multiple documents, seeBulk.find.update().Bulk.find.updateOne()는 다음 매개 변수를 허용합니다.Parameter유형설명문서 또는 파이프라인
수정 사항을 적용합니다. 다음 중 하나일 수 있습니다.
Update document:
업데이트 연산자 표현식만 포함합니다.
업데이트 수정 매개변수에 대한 자세한 내용은
db.collection.updateOne()참조 페이지를 참조하세요.Bulk.find()의 연관된<query>문서와 업데이트 문서의 합은 최대 BSON 문서 크기 이하여야 합니다.이 작업에 대해 upsert: true를 지정하려면
Bulk.find.upsert()와 함께 사용하세요.특정 배열 요소를 업데이트하기 위해
arrayFilters를 지정하려면Bulk.find.arrayFilters()와 함께 사용하세요.연계된
Bulk.find()에 사용할 인덱스를 지정하려면Bulk.find.hint()를 참조하세요.문서 전체를 대체하려면
Bulk.find.replaceOne()도 참조하세요.
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
참고
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
행동
<update> 문서에 다음과 같이 업데이트 연산자 표현식만 포함된 경우:
{ $set: { status: "D" }, $inc: { points: 2 } }
Then, Bulk.find.updateOne() updates only the corresponding fields, status and points, in the document.
예시
The following example initializes a Bulk() operations builder for the items collection, and adds various updateOne() operations to the list of operations.
var bulk = db.items.initializeUnorderedBulkOp(); bulk.find( { status: "D" } ).updateOne( { $set: { status: "I", points: "0" } } ); bulk.execute();
집계 파이프라인으로 업데이트하기
업데이트 메서드는 집계 파이프라인을 허용할 수 있습니다. 예를 들어 다음과 같은 용도로 사용할 수 있습니다.
현재 날짜/시간으로 해석되며
$currentDate업데이트 연산자 표현식과 유사한 동작을 제공할 수 있는 집계 변수NOW입니다. 집계 변수에 액세스하려면 변수 앞에 이중 달러 기호($$)를 붙이고 따옴표로 묶습니다.
var bulk = db.items.initializeUnorderedBulkOp(); bulk.find( { status: "P" } ).updateOne( [ { $set: { points: 0, lastModified: "$$NOW" } } ] ); bulk.execute();