You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Farès Hassak (JIRA)" <ji...@apache.org> on 2018/02/27 22:19:00 UTC

[jira] [Created] (CAMEL-12302) camel-mongodb : Support for bulk writes operation

Farès Hassak created CAMEL-12302:
------------------------------------

             Summary: camel-mongodb : Support for bulk writes operation
                 Key: CAMEL-12302
                 URL: https://issues.apache.org/jira/browse/CAMEL-12302
             Project: Camel
          Issue Type: New Feature
          Components: camel-mongodb, camel-mongodb3
            Reporter: Farès Hassak


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 :
{code:java}
// 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);
{code}
      
An header with key CamelMongoDbBulkOrdered will be added (true is the default value).

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

Later, i will add support for String :
{code:java}
// route: from("direct:bulk").to("mongodb:myDb?database=science&collection=notableScientists&operation=bulkWrite");

template.requestBody("direct:bulkWrite", "[ { \"insertOne\" : { \"document\" : { \"scientist\" : \"Marie Curie\" }}}," + 
"	{ \"updateOne\" : { \"filter\" : { \"_id\" : 1 }, \"update\" : { \"$set\" : { \"scientist\" : \"Albert Einstein\" }}}}," + 
"   { \"deleteOne\" : { \"filter\" : { \"_id\" : 2} }} ]");
{code}

I will do 2 PR.

Farès



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)