Hi

I created a ticket
https://issues.apache.org/jira/browse/CAMEL-15646

On Mon, Oct 5, 2020 at 7:01 PM Site Register
<site.regis...@ymail.com.invalid> wrote:
>
>  Can somebody help to create a jira for this because I don't have the 
> permission?
> Please use below codes to reproduce.
>
> @Named("ConvertType")
> @Log4j2
> public class ConvertType implements Processor {  private static final Logger 
> logger = LoggerFactory.getLogger(ConvertType.class);  @Override
>  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();
>  List<Document> taxGroupList = new ArrayList<Document>();
>  taxGroupList.add(a);
>  taxGroupList.add(b);
>  taxGroupList.add(c);
>  exchange.getIn().setBody(taxGroupList);
>   // From MongoDbProducer.java#L428
>  // 
> https://github.com/apache/camel/blob/af7e383e9fc1d25ce9665f74d33672cc5b507952/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java#L428
>  Object insert = 
> exchange.getContext().getTypeConverter().tryConvertTo(Document.class, 
> exchange, exchange.getIn().getBody());
>  if (insert == null)
>  logger.info(Document.class.getTypeName() + " mismatched with " + 
> exchange.getIn().getBody().getClass().getTypeName());
>  else
>  logger.info(Document.class.getTypeName() + " matched with " + 
> exchange.getIn().getBody().getClass().getTypeName());
>  } }
>
> from(fromKafka)    .process("ConvertType");
>     On Monday, October 5, 2020, 03:30:38 AM EDT, Claus Ibsen 
> <claus.ib...@gmail.com> wrote:
>
>  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



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

Reply via email to