// route: from("direct:aggregate").to("mongodb:myDb?database=science&collection=notableScientists&operation=aggregate");
List<Bson> aggregate = Arrays.asList(match(or(eq("scientist", "Darwin"), eq("scientist",
group("$scientist", sum("count", 1)));
from("direct:aggregate")
.setBody().constant(aggregate)
.to("mongodb:myDb?database=science&collection=notableScientists&operation=aggregate")
.to("mock:resultAggregate");
// route: from("direct:aggregate").to("mongodb:myDb?database=science&collection=notableScientists&operation=aggregate");
List<Bson> aggregate = Arrays.asList(match(or(eq("scientist", "Darwin"), eq("scientist",
group("$scientist", sum("count", 1)));
from("direct:aggregate")
.setBody().constant(aggregate)
.to("mongodb:myDb?database=science&collection=notableScientists&operation=aggregate")
.to("mock:resultAggregate");
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
デフォルトでは、すべての結果のリストが返されます。これは、結果のサイズによってはメモリーに大きくなる可能性があります。より安全な代替手段は、outputType=MongoIterable を設定することです。次のプロセッサーでは、メッセージ本文に iterable が表示されます。これにより、結果を 1 つずつステップスルーできます。したがって、バッチサイズを設定し、反復可能を返すと、結果を効率的に取得および処理できます。
List<Bson> aggregate = Arrays.asList(match(or(eq("scientist", "Darwin"), eq("scientist",
group("$scientist", sum("count", 1)));
from("direct:aggregate")
.setHeader(MongoDbConstants.BATCH_SIZE).constant(10)
.setBody().constant(aggregate)
.to("mongodb:myDb?database=science&collection=notableScientists&operation=aggregate&outputType=MongoIterable")
.split(body())
.streaming()
.to("mock:resultAggregate");
List<Bson> aggregate = Arrays.asList(match(or(eq("scientist", "Darwin"), eq("scientist",
group("$scientist", sum("count", 1)));
from("direct:aggregate")
.setHeader(MongoDbConstants.BATCH_SIZE).constant(10)
.setBody().constant(aggregate)
.to("mongodb:myDb?database=science&collection=notableScientists&operation=aggregate&outputType=MongoIterable")
.split(body())
.streaming()
.to("mock:resultAggregate");
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow