Reputation: 163
I'm new user of mongoDB, I have create an application with spring boot/mySql and I want replace database sql to mongoDB.
I did change all things necessary for example, annotations, relations etc ... but I have a problem with request I don't know the similar syntax of @Query in mongoDb.
this my request with sql:
// this calculate the sum of all distance in walk's document
@Query("select sum(distance) from Walk")
public Double sumDistance();
I did read mongoDB aggregate and I know how to use it in console windows with command
$ mongo
$ db.walk.aggregate([{$group:{"_id":"$dateWalk",Count:{$sum:"$distance"}}}])
but, I want use $sum in my program java not in console.
So please, I need your help about the syntax similar to this with mongoDB
// this calculate the sum of all distance in walk's document
@Query("select sum(distance) from Walk")
public Double sumDistance();
thanks in advance :)
Upvotes: 1
Views: 2193
Reputation: 9497
You would need to create a custom Repository that would implement the aggregation.
Examples:
Upvotes: 1