2017-08-24 77 views
1

我使用以下聚合来计算具有特定“alertsources.date_creation”的文档“alert”上的“alertsources”,但我不知道为什么它计数所有alertsources而不是那些拥有标准:春天的数据Mongo数据库聚合

final Aggregation aggregation = Aggregation.newAggregation(
       Aggregation.match(Criteria.where("alertsources.date_creation").regex(date)), 
       Aggregation.match(Criteria.where("descA").is(alertName)), 

       //regex(".*"+date+".*") 
       Aggregation.unwind("alertsources"), 
       Aggregation.unwind("descA"), 
       Aggregation.group().count().as("count")); 

     //System.out.println("----------"+mongoTemplate.aggregate(aggregation, Alert.class, MentionCount.class).getRawResults()+"-----"); 
     List<MentionCount> agregResult = mongoTemplate.aggregate(aggregation, Alert.class, MentionCount.class).getMappedResults(); 

回答

0

我解决了这个问题,我已经申请$比赛之前和$开卷后:

Aggregation.match(Criteria.where("alertsources.date_creation").regex(".*"+date+".*")), 
       Aggregation.match(Criteria.where("descA").is(alertName)), 

       //regex(".*"+date+".*") 
       Aggregation.unwind("alertsources"), 
       Aggregation.unwind("descA"), 
       Aggregation.match(Criteria.where("alertsources.date_creation").regex(".*"+date+".*")), 
       Aggregation.group().count().as("count") 

全部归功于@Neil Lunn,做研究后,我发现他原来answer上此事。