java - How to make numeric comparison when using morphia to perform an $elemMatch query -


my document has following structure:

{ "scores": [{     "scoretitle": "environment",     "scorevalue": 3,     "scoredescribe": "good" }, {     "scoretitle": "service",     "scorevalue": 3,     "scoredescribe": "good" }, {     "scoretitle": "taste",     "scorevalue": 4,     "scoredescribe": "good" }] } 

in mongo shell, can use following query find document has score title 'environment' , value greater 2.

db.reviews.find({"scores":{"$elemmatch":{"scorevalue":{"$gt":2},"scoretitle":"environment"}}}) 

now want query document using morphia, api doc, 'elem' operator supported in fiter method, , additional query criteria object required, example, query document has score title "environment" , describe "good":

score score = new score();// criteria object, support comparisons of equality score.setscoretitle("environment"); // title should environment score.setscoredescribe("good"); // describe should query q = ds.createquery(review.class).filter("scores elem", score); 

my question is: how can make numeric comparison in query criteria, say, how can make query has same effect mongo shell counterpart.

i guess can try

ds.createquery(review.class).   filter("scores.scorevalue >=", 2).   filter("scores.scoretitle", "environment").   retrievedfields(true, "scores.$") 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -