'MongoDb to spingboot
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"}}}\])
This is my mongo aggregate query and want to use in spring boot. please share your solution
your text
This is my mongo aggregate query and want to use in spring boot. please share your solution
Solution 1:[1]
The simplest way is to define the below method in the DAO interface:
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);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ali Mohammadi |
