1

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 :)

2

1 Answer 1

1

You would need to create a custom Repository that would implement the aggregation.

Examples:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.