Answer the question
In order to leave comments, you need to log in
Query in MongoDB using Jongo?
I have a MongoDB query that works:
db.stores.aggregate([ { $unwind: "$listProducts" }, { $match : { "listProducts.productPrice" : { $ne : 0 } } }, { $group : { _id : { storeName : "$storeName", }, MAX_Products : { $max : "$listProducts.productPrice" } } } ])
how can I write the same query using Jongo?
i tried like this:
Aggregate.ResultsIterator max = stores.aggregate("{$unwind:{$listProducts}") .and("{$match:{$listProducts.productPrice $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}
Answer the question
In order to leave comments, you need to log in
So that was the question - how to write this syntactically correctly using Jongo.
Unfortunately Jongo's documentation is very short, and I didn't find any example with unwind, I wrote dozens of query options, but I couldn't "guess" the correct syntax, so I turned to the forum, in the hope that someone could know it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question