검색

228.5.2.3. update

download PDF

컬렉션에서 하나 이상의 레코드를 업데이트합니다. 필터 쿼리 및 업데이트 규칙이 필요합니다.

MongoDBConstants.CRITERIA 헤더를 Bson 으로 사용하여 필터를 정의하고 본문에서 Bson 으로 업데이트 규칙을 정의할 수 있습니다.

두 번째 방법은 List<Bson>이 정확히 2개의 요소를 포함하는 IN 메시지 본문으로 필요합니다.

  • 요소 1 (index 0) ECDHE 필터 쿼리 ECDSA는 일반적인 쿼리 개체와 동일한 영향을 받을 개체를 결정합니다.
  • 요소 2 (index 1) 일치 오브젝트의 업데이트 규칙을 업데이트합니다. MongoDB 의 모든 수정자를 지원합니다.
참고

Multiupdates . 기본적으로 MongoDB는 여러 오브젝트가 필터 쿼리와 일치하는 경우에도 1개의 오브젝트만 업데이트합니다. MongoDB에 일치하는 모든 레코드를 업데이트하도록 지시하려면 CamelMongoDbMultiUpdate IN 메시지 헤더를 true 로 설정합니다.

CamelMongoDbRecordsAffected 헤더가 반환되고(MongoDbConstants.RECORDS_AFFECTED 상수)로 업데이트된 레코드 수( WriteResult.getN()에서 분리됨)가 반환됩니다.

다음 IN 메시지 헤더를 지원합니다.

헤더 키빠른 일정description (MongoDB API doc에서 추출)예상 유형

CamelMongoDbMultiUpdate

MongoDbConstants.MULTIUPDATE

업데이트가 모든 오브젝트 일치에 적용되는 경우. 자세한 내용은 http://www.mongodb.org/display/DOCS/Atomic+Operations

부울/Boolean

CamelMongoDbUpsert

MongoDbConstants.UPSERT

데이터베이스가 없는 경우 해당 요소를 만들어야 하는 경우If the database should create the element if it does not exist.

부울/Boolean

예를 들어, 다음 명령은 "scientist" 필드의 값을 "Darwin"으로 설정하여 filterField 필드가 true인 모든 레코드를 업데이트합니다.

// route: from("direct:update").to("mongodb3:myDb?database=science&collection=notableScientists&operation=update");
Bson filterField = Filters.eq("filterField", true);
String updateObj = Updates.set("scientist", "Darwin");
Object result = template.requestBodyAndHeader("direct:update", new Bson[] {filterField, Document.parse(updateObj)}, MongoDbConstants.MULTIUPDATE, true);
// route: from("direct:update").to("mongodb3:myDb?database=science&collection=notableScientists&operation=update");
Maps<String, Object> headers = new HashMap<>(2);
headers.add(MongoDbConstants.MULTIUPDATE, true);
headers.add(MongoDbConstants.FIELDS_FILTER, Filters.eq("filterField", true));
String updateObj = Updates.set("scientist", "Darwin");;
Object result = template.requestBodyAndHeaders("direct:update", updateObj, headers);
// route: from("direct:update").to("mongodb3:myDb?database=science&collection=notableScientists&operation=update");
String updateObj = "[{\"filterField\": true}, {\"$set\", {\"scientist\", \"Darwin\"}}]";
Object result = template.requestBodyAndHeader("direct:update", updateObj, MongoDbConstants.MULTIUPDATE, true);
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.