MongoDB and Spring Data. Get size of array in entity -



MongoDB and Spring Data. Get size of array in entity -

i have such entity.

@document public class entity{ @id private string id; private set<integer> ids; }

i need size of array ids

how can done using spring info aggregation framework?

i'm trying this:

aggregationoperation match = aggregation.match(where("id").is(id)); aggregationoperation grouping = aggregation.group("ids"); aggregation aggregation = aggregation.newaggregation(match, group); template.aggregate(aggregation, entity.class, entity.class);

seems i'm doing totally wrong.

you can utilize this;

aggregation aggregation = newaggregation(match(criteria),group("ids").count().as("count"));

this produce :

{"yourpojo":[{"ids":[...],"count":5},...]}

spring-data-mongodb

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -