// route: from("direct:aggregate").to("mongodb3: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("mongodb3:myDb?database=science&collection=notableScientists&operation=aggregate")
    .to("mock:resultAggregate");
// route: from("direct:aggregate").to("mongodb3: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("mongodb3:myDb?database=science&collection=notableScientists&operation=aggregate")
    .to("mock:resultAggregate");
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
 
 
						默认情况下,返回所有结果的列表。根据结果的大小,这可能会对内存进行重量。更安全的方法是设置 outputType=MongoIterable。下一个处理器将在消息正文中看到一个不可避免的,允许它按一步调试结果。因此,设置批处理大小并返回它可允许有效地检索和处理结果。
					
						您还可以通过包含 outputType=DBCursor (Camel 2.21+)作为 endpoint 选项,从服务器返回至您的路由的文档可能比设置上述标头更简单。这了来自 Mongo 驱动程序的 DBCursor,就像您在 Mongo shell 中执行 aggregate ()一样,允许您的路由迭代结果。默认情况下,如果不使用此选项,此组件会将驱动程序的光标中的文档加载到列表,并将此数据返回到您的路由 - 这可能导致大量内存对象。请记住,使用 DBCursor 并不要求提供匹配的文档数量 - 请参阅 MongoDB 文档网站了解详细信息。
					
// route: from("direct:aggregate").to("mongodb3:myDb?database=science&collection=notableScientists&operation=aggregate&outputType=MongoIterable");
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("mongodb3:myDb?database=science&collection=notableScientists&operation=aggregate&outputType=MongoIterable")
    .split(body())
    .streaming()
    .to("mock:resultAggregate");
// route: from("direct:aggregate").to("mongodb3:myDb?database=science&collection=notableScientists&operation=aggregate&outputType=MongoIterable");
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("mongodb3:myDb?database=science&collection=notableScientists&operation=aggregate&outputType=MongoIterable")
    .split(body())
    .streaming()
    .to("mock:resultAggregate");
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow