On Sun, Oct 4, 2020 at 9:02 PM Site Register
<site.regis...@ymail.com.invalid> wrote:
>
>  I went through Camel MongoDB source code 
> (https://github.com/apache/camel/blob/af7e383e9fc1d25ce9665f74d33672cc5b507952/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java#L424)
> I found on line 428, it returns not null for trying to convert List<Document> 
> which caused boolean singleInsert always equals to true.
> // Always return the first document of the list
> Object insert = 
> exchange.getContext().getTypeConverter().tryConvertTo(Document.class, 
> exchange, exchange.getIn().getBody());
>
>
> Is this a bug?

Ah yeah if it just grabs first element from the list. Can you create a
JIRA. You are also welcome to work on a PR with a fix

> Thank you,    On Saturday, October 3, 2020, 08:29:38 PM EDT, Site Register 
> <site.regis...@ymail.com> wrote:
>
>   Thank you Claus,
> I went to 
> https://github.com/apache/camel/blob/master/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
>  and simplified my codes but still got the same results. We had a project and 
> I tried to convince to leverage Camel features. Any helps will be very 
> appreciated.
>
> Thank you,
>  /* My Sample Codes */
>  from(fromKafka)
>  .log("Starting...")
>  .process("CreateDocumentList")
>  
> .to("mongodb:mongoBean?database=databaseName&collection=collectionName&operation=insert")
>  .log("I am done");
>
>
> @Named("CreateDocumentList")
> public class CreateDocumentList implements Processor {
> public void process(Exchange exchange) {
>  Document a = new Document(MongoDbConstants.MONGO_ID, "testInsert1");  
> a.append("MyId", 1).toJson();  Document b = new 
> Document(MongoDbConstants.MONGO_ID, "testInsert2");  b.append("MyId", 
> 2).toJson();  Document c = new Document(MongoDbConstants.MONGO_ID, 
> "testInsert3");  c.append("MyId", 3).toJson();  ArrayList<Document> 
> taxGroupList = new ArrayList<Document>();  taxGroupList.add(a);  
> taxGroupList.add(b);  taxGroupList.add(c);  
> exchange.getIn().setBody(taxGroupList); }
> }
> Results: According to Camel MongoDb document, I expect to see 3 rows being 
> inserted but I can only see one row.
>
> /* MongoDb document: 
> https://camel.apache.org/components/latest/mongodb-component.html#_createupdate_operations
>  */
>
> For multiple insert, the endpoint will expect a List, Array or Collections of 
> objects of any type, as long as they are - or can be converted to - Document. 
> Example:
> from("direct:insert")
>     .to("mongodb:myDb?database=flights&collection=tickets&operation=insert");
>
>
> Results in MongoDb:
> {     "_id" : "testInsert1",
>     "MyId" : NumberInt(1)
> }
>
>
>
>
>
>
>     On Saturday, October 3, 2020, 03:15:28 AM EDT, Claus Ibsen 
> <claus.ib...@gmail.com> wrote:
>
>  Hi
>
> It can be a good idea to look at the unit tests of the components as
> they often cover how a functionality may be used (if tested) or at
> least help you in the right direction.
>
>
> On Sat, Oct 3, 2020 at 12:14 AM Site Register
> <site.regis...@ymail.com.invalid> wrote:
> >
> >  Hi All,
> > According to the document MongoDB :: Apache Camel , it supposes to batch 
> > insert into mongodb. However I found it only inserted the first record of 
> > the batch. I also added a process right before mongodb insert and the 
> > message having a list of the document. Very appreciated if you can help.
> > Thank you,
> >
> >    On Thursday, October 1, 2020, 08:22:23 AM EDT, Site Register 
> > <site.regis...@ymail.com.invalid> wrote:
> >
> >  Hi All,
> > It tried to batch insert by leveraging aggregate. Somehow it only inserted 
> > one record for each batch. Very appreciated if you can help.
> > from(fromFile)
> >  .split().tokenize("\n",1)
> >  .aggregate(constant(true), new ArrayListAggregationStrategy())
> >  .completionSize(1000)
> >  .completionTimeout(500)
> >  
> > .to("mongodb:mongoBean?database=databaseName&collection=collectionName&operation=insert");
> >
> > Thank you,
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to