mongo基本操作

//1.分组查询
Aggregation agg=Aggregation.newAggregation(
                Aggregation.match(Criteria.where("tenantId").is(TenantUtils.getTenantId()).and("ancestor._id").is(id).and("vmallOnShelf").is(true)),
                Aggregation.group("goodsId").push(Aggregation.ROOT).as("goodsList").first("vmallPrice").as("vmallPrice"),
                Aggregation.sort(direction, "vmallPrice"),
                Aggregation.skip(m),
                Aggregation.limit(n)

            );
        List list = mongoTemplate.aggregate(agg,"goods", GoodsSKU.class).getMappedResults();
        return list.stream().map(GoodsSKU::getFirstGoods).collect(Collectors.toList());

你可能感兴趣的:(mongo操作)