My document has the following structure:
{ "scores": [{ "scoreTitle": "environment", "scoreValue": 3, "scoreDescribe": "good" }, { "scoreTitle": "service", "scoreValue": 3, "scoreDescribe": "good" }, { "scoreTitle": "taste", "scoreValue": 4, "scoreDescribe": "good" }] }
In the mongo shell, I can use the following query to find a document that has a rating whose heading is "medium" and the value is greater than 2.
db.reviews.find({"scores":{"$elemMatch":{"scoreValue":{"$gt":2},"scoreTitle":"environment"}}})
Now I want to request a document using morphia, from api doc, the 'elem' operator is supported in the fiter method, and an additional request criteria object is required, for example, a request for a document that has a rating, title is βenvironmentβ, and description is βgoodβ :
Score score = new Score();// the criteria object, only support comparisons of equality score.setScoreTitle("environment"); // title should be environment score.setScoreDescribe("good"); // describe should be good Query q = ds.createQuery(Review.class).filter("scores elem", score);
My question is: how can I make a numerical comparison in the query criteria, that is, how can I make a query that has the same effect as a copy of the mongo shell.