您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用spring-data-mongodb传输聚合操作的结果

使用spring-data-mongodb传输聚合操作的结果

对于那些仍在寻找答案的人:

从spring-data-mongo版本2.0.0.M4开始( )MongoTemplate得到了一种aggregateStream方法

因此,您可以执行以下操作:

 AggregationOptions aggregationOptions = Aggregation.newAggregationOptions()
        // this is very important: if you do not set the batch size, you'll get all the objects at once and you might run out of memory if the returning data set is too large
        .cursorBatchSize(mongoCursorBatchSize)
        .build();

    data = mongoTemplate.aggregateStream(Aggregation.newAggregation(
            Aggregation.group("person_id").count().as("count")).withOptions(aggregationOptions), collectionName, YourClazz.class);
mongodb 2022/1/1 18:25:31 有510人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶