I have made Aggregations.lookup from two collections, that returned list of stores, each having field of array of displayed products, with each product having its price. The task is to receive projection, showing for each shop:
- Total amount of products
- Avg products price
- Price of the most expensive and the cheapest product
- And amount of products with price less than 10
The problem is I don't understand exactly how to fulfill the fourth task, cause i don't quite understand the syntax of projections.computed. Here's code
AggregateIterable<Document> it = storesCollection.aggregate(Arrays.asList(
lookup("Products", "products", "name", "products_displayed")
, project(fields(
include("name")
, excludeId()
, computed("total", computed("$size", "$products_displayed")) //total
, computed("avgprice", computed("$avg", "$products_displayed.price")) //avg
, computed("maxprice", computed("$max", "$products_displayed.price")) //max
, computed("minprice", computed("$min", "$products_displayed.price")) //min
, computed("total lt 10", computed("$size", )) // this is the problem: count total amount of products with prices less than 10
)
)
)
);