aggregate(\[{"$match" : {"date": { "$l t": new Date(), "$g t e": new Date(new Date().set
Date(new Date().get Date()-7))}}},
{your text"$group": {"\_id" : "$date","quantity" : { $sum : "$quantity"}}}\])这是我的mongo聚合查询,希望在spring引导中使用。请分享您的解决方案,your text,这是我的mongo聚合查询,希望在spring中使用。请分享您的解决方案。
发布于 2022-04-06 11:41:47
最简单的方法是在DAO接口中定义以下方法:
public interface ISampleDAO extends JpaRepository<T, Long> {
@Aggregation(pipeline ={"{'$match':{'date':{$lt:'?0',$gte:'?1'}}}","{'$group':{'_id':'$date','quantity':{'$sum':'$quantity'}}}"})
List<T> getResult(Date ltDate,Date gteDate);
}https://stackoverflow.com/questions/71720662
复制相似问题