2

I have the following excerpt of code:

@Component
public class RetrievalAllFromDbRoute extends RouteBuilder{
    public void configure() throws Exception {
        this.from("direct:allObjects").routeId("retrieveAllObjectsFromDB")
                .setHeader("CamelMongoDbBatchSize", constant(50))
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        DBObject fieldFilter = BasicDBObjectBuilder.start().add("_id", 1).get();
                        exchange.getMessage().setHeader(MongoDbConstants.FIELDS_FILTER, fieldFilter);
                    }
                })
                .to("mongodb:mongoClient?database="+mongoDbName +"&collection=myObjectCollection&operation=findAll&outputType=DBCursor")
                .split(body())
                .streaming()
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        JsonNode idNode = UtilMethods.convertStringToJson(exchange.getMessage().getBody().toString());
                        exchange.getMessage().setBody(idNode.get("_id").asText());
                        System.out.println("\n Extracted id["+exchange.getMessage().getBody().toString()+"] from db \n");
                    }
                });
    }
}

However I am only getting a single output. Setting a break point and querying of the db in the first prcessor reveals that there are over 300 objects in the database, so I don't understand why I am only getting 1 object.

EDIT:
My maven POM dependency:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-mongodb</artifactId>
    <version>2.22.0</version>
</dependency>

working with a MongoDB 3.6 database

Dark Star1
  • 6,986
  • 16
  • 73
  • 121
  • 1
    Strange, this should work according [this gist](https://gist.github.com/padewitte/1e159475b0ae7a9b6b8e). Could you confirm, you are using `camel-mongo` component and not `camel-mongodb3` component? Which version of Camel and component you are using? – Bedla Nov 25 '18 at 13:28
  • @Bedla I'm using the `camel-mongodb` component from the 2.22.0 maven plugin. I am however switching to the `camel-mongodb3` version now to see if this makes a difference since the underlying db is mongo3.6 – Dark Star1 Nov 26 '18 at 14:59
  • During migration keep in mind, that [outputType DBCursor is renamed to MongoIterable in `camel-mongo3`](https://github.com/apache/camel/blob/master/components/camel-mongodb3/src/main/docs/mongodb3-component.adoc). Source [here](https://github.com/apache/camel/pull/2561) – Bedla Nov 26 '18 at 19:59
  • @Bedla Nothing has changed. The iterable still only returns one document – Dark Star1 Nov 27 '18 at 10:11

0 Answers0