Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-12302

camel-mongodb : Support for bulk writes operation

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 2.21.0
    • None
    • Unknown

    Description

      Hello,

      To improve write performance, we need support for bulk operations :

      https://mongodb.github.io/mongo-java-driver/3.6/driver/tutorials/bulk-writes/
      https://docs.mongodb.com/manual/core/bulk-write-operations/

      I will add new bulkWrite operation that expect a list of WriteModel Object in body.

      Example :

      // route: from("direct:bulkWrite").to("mongodb:myDb?database=science&collection=notableScientists&operation=bulkWrite");
      
      List<WriteModel<DBObject>> bulkOperations = Arrays.asList(
                      new InsertOneModel<>(new BasicDBObject("scientist", "Descartes")),
                      new InsertOneModel<>(new BasicDBObject("scientist", "Pierre Curie")),
                      new UpdateOneModel<>(new BasicDBObject("_id", "5"), new BasicDBObject("$set", new BasicDBObject("scientist", "Marie Curie"))),
                      new DeleteOneModel<>(new BasicDBObject("_id", "2")));
      
      BulkWriteResult result = template.requestBody("direct:bulkWrite", bulkOperations, BulkWriteResult.class);
      

      An header with key CamelMongoDbBulkOrdered will be added (true is the default value).

      BulkWriteResult result = template.requestBodyAndHeader("direct:bulkWrite", bulkOperations, MongoDbConstants.BULK_ORDERED, false, BulkWriteResult.class)
      

      Later, i will add support for String :

      // route: from("direct:bulk").to("mongodb:myDb?database=science&collection=notableScientists&operation=bulkWrite");
      
      template.requestBody("direct:bulkWrite", "[
       { \"insertOne\" : { \"document\" : { \"scientist\" : \"Descartes\" }}},
       { \"insertOne\" : { \"document\" : { \"scientist\" : \"Pierre Curie\" }}},
       { \"updateOne\" : { \"filter\" : { \"_id\" :  \"5\" }, \"update\" : { \"$set\" : { \"scientist\" : \"Marie Curie\" }}}},
       { \"deleteOne\" : { \"filter\" : { \"_id\" : 2} }} ]");
      

      I will do 2 PR.

      Farès

      Attachments

        Activity

          People

            acosentino Andrea Cosentino
            fhassak Farès Hassak
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: