How do I write a query using Jongo?

24 views
Skip to first unread message

Vitaly Gusev

unread,
Sep 13, 2021, 8:42:19 AM9/13/21
to Jongo
I have a simple (working) query from unwind to MongoDB, how can I write this query using Jongo?
 db.stores.aggregate([ { $unwind: "$listProducts" }, { $match : { "listProducts.productPrice" : { $ne : 0 } } }, { $group : { _id : { storeName : "$storeName", }, MAX_Products : { $max : "$listProducts.productPrice" } } } ])

What I have tried:
Aggregate.ResultsIterator max = stores.aggregate("{$unwind:{$listProducts}") .and("{$match:{ $ne : 0 }") .and("{$group:{$storeName}") .and("{$max:{$listProducts.productPrice}") .as(Store.class);

 but I get Exception in thread "main" java.lang.IllegalArgumentException: Cannot parse query: {$unwind:{$listProducts}
Reply all
Reply to author
Forward
0 new messages