使用 WSO2EI 和 MongoDB 的自定义聚合

Custom aggregation with WSO2EI and MongoDB

我正在尝试在 WSO2DSS(在 WSO2EI 中)中为 Mongo 数据服务实施聚合操作,因为如前所述 . So I cloned WSO2EI code version 4.4.10 (our team happens to be using this version) and I've successfully added some of my own functionality. However, whenever I try to use org.jongo.MongoCollection.aggregate() function, I get error Error in MongoQuery.runQuery: Command failed with error 9: 'The 'cursor' option is required, except for aggregate with the explain argument'. I checked all the posts regarding this issue and tried to use different versions of Mongo driver (3.4, 3.6..), also changed the actual syntax a lot but no matter what I try, I always get this error if I use the .aggregate() function. Also should I be using org.jongo.MongoCollection.aggregate(String pipelineOperator) or com.mongodb.async.client.aggregate(java.util.List<? extends Bson> pipeline) as stated in the Mongo Java 3.6 documentation here 仅支持开箱即用的基本操作,如 CRUD 和计数。我使用的示例代码:

private Iterator<MongoTestClass> doAggregate1(MongoCollection collection, String opQuery, Object[] parameters) throws DataServiceFault {

        return collection.aggregate("{$match:{componentType:'Endpoint'}}")
                .as(MongoTestClass.class).iterator();

    }

其中 componentType 是我的 MongoDB 集合文档中的现有字段,'Endpoint' 是它的值。我的实际语法错误吗?还是有其他问题?如何将 'cursor' 添加到我的查询中以便错误消失?

我无法理解这是如何工作的...非常感谢任何帮助。

来自文档。

MongoDB 3.4 deprecates the use of aggregate command without the cursor option, unless the pipeline includes the explain option. When returning aggregation results inline using the aggregate command, specify the cursor option using the default batch size cursor: {} or specify the batch size in the cursor option cursor: { batchSize: }.

您可以将 batchSizeAggregationOptions 传递给 Jongo 聚合方法。

AggregationOptions options = AggregationOptions.builder().options.
     batchSize(100).
     outputMode(AggregationOptions.OutputMode.CURSOR).build();

collection.aggregate("{$match:{componentType:'Endpoint'}}").options(options).as(MongoTestClass.class).iterator();

默认批量大小

AggregationOptions options = AggregationOptions.builder().options.
     outputMode(AggregationOptions.OutputMode.CURSOR).build();

AggregationOptions options = AggregationOptions.builder().build();

collection.aggregate("{$match:{componentType:'Endpoint'}}").options(options).as(MongoTestClass.class).iterator();