-3

我试图在java中转换mongo查询,但java代码无法正常工作,这将在组colums中给出空值。以上mongo查询在shell中工作正常,如何使用灌溉在java代码中进行转换。mongodb聚合组适用于java中的多个colums

蒙戈查询: -

db.journalEntryRevised.aggregate(
{ 
     $group : { 
      _id : {nameOfGLAccount:"$nameOfGLAccount",transactionType:"$transactionType"}, 
      calculatedBaseCurrencyAmount: { $sum:"$calculatedBaseCurrencyAmount" }, 
     } 
    } 

Java代码: - 在弹簧蒙戈分贝

Aggregation aggregationOpningDrAccount = newAggregation(
      match(Criteria.where("enterpriseId").is(clientUser.getEnterpriseId())), 
      match(Criteria.where("jedate").lt(startDate)), 
      match(Criteria.where("fund").is(fund)), 
      match(Criteria.where("transactionType").is("DR")), 
      group("nameOfGLAccount").sum("calculatedBaseCurrencyAmount").as("calculatedBaseCurrencyAmount").first("transactionType").as("transactionType")); 
      AggregationResults openingDrAccountResult = mongoTemplate.aggregate(aggregationOpningDrAccount,"journalEntryRevised", TrialBalance.class); 
      List <TrialBalance>openBalanceDrAccount=openingDrAccountResult.getMappedResults(); 
+0

你试过没有比赛阶段?看看它是否工作 – Veeram

+0

是它给输出: - [ { “ID”:无效, “calculatedBaseCurrencyAmount”:9561 }, { “ID”:无效, “calculatedBaseCurrencyAmount”:9571444 }, { “ID”:空, “calculatedBaseCurrencyAmount”:1000 }, { “ID”:空, “calculatedBaseCurrencyAmount”:1000 } –

+0

预期输出: - { “_id”:{ “nameOfGLAccount”: “897佣金费用”, “TRANSACTIONTYPE”: “CR” }, “calculatedBaseCurrencyAmount”:9561.0 } /* 2 */ { “_id”:{ “nameOfGLAccount”: “789-由于向/从经纪人”, “TRANSACTIONTYPE”: “DR” }, “calculatedBaseCurrencyAmount”:9571444.0 } /* 3 */ { “_id”:{ “nameOfGLAccount”: “321-证券投资,(收费)” , “transactionType”:“CR” }, “calculatedBas eCurrencyAmount“:1000.0 } –

回答

0
Group

阶段需要可变ARGS。

尝试

group("nameOfGLAccount", "transactionType")

,并添加transactionTypeTrialBalance POJO。