Convert MongoDB query into Spring MongoDB syntax

前端 未结 2 1497
春和景丽
春和景丽 2021-01-27 18:06

Hello I am unable to convert the following mongoDB query into spring query, i have tried multiple ways, but did not get the result.

db.getCollection(\'FarmerCrop         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 18:23

    Have you ever thought about using MongoDB compass? It will make your work very simple.

    1. Open MongoDB compass connect to your instance
    2. Aggregation tab, construct your pipeline
    3. click on the 3 dots(...) next to save pipeline option
    4. Select export to language and select Java
    5. Your query is ready

    Here is the java query

    Arrays.asList(match(and(eq("cropData.crop", "RICE"), lt("creationTime", 1551447981473.0d))), group(new BsonNull(), avg("average", "$cropData.cropPrice"), max("max", "$cropData.cropPrice"), min("min", "$cropData.cropPrice")))
    

提交回复
热议问题