0

This is Criteria Query

Query query = new Query();
        query.addCriteria(Criteria.where("careGiverId").is(careTakerId));
        query.addCriteria(Criteria.where("careType").is(careType));         
        return mongoOperations.count(query,  CareLogBean.class);

How to apply Mongodb Aggregations on this...i will return count ....help me thanks in advance

1 Answers1

0

You can try something like below for Mongo Server 3.4 version with Spring Mongo 1.10.1.Release. Uses $count aggregation operator.

 AggregationOperation match = Aggregation.match(Criteria.where("careGiverId").is(careTakerId).and("careType").is(careType));
 AggregationOperation count = Aggregation.count().as("count");
 Aggregation agg = Aggregation.newAggregation(match, count);
 mongoOperations.aggregate(agg, CareLogBean.class);
s7vr
  • 73,656
  • 11
  • 106
  • 127