Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$elemMatch multiple criteria support #970

Closed
elogunov opened this issue Jul 20, 2016 · 1 comment · Fixed by #985
Closed

$elemMatch multiple criteria support #970

elogunov opened this issue Jul 20, 2016 · 1 comment · Fixed by #985
Milestone

Comments

@elogunov
Copy link

Correct me if I am wrong but as I can see current Morphia implementation of $elemMatch (i.e. FieldEnd#hasThisElement) doesn't support multiple criteria for array elements or multiple criteria for array of documents.
So there is no way to create such query using morphia:
db.restaurants.find({grades : { $elemMatch:{"score":{$gt : 80 , $lt :100}}}})
stackoverflow question

I didn't find any linked issues here.

@evanchooly
Copy link
Member

If you can build and test the 'hasThisElement' branch, I have a fix that I think will get you what you need. Building on the existing tests, this is what the test for the new elemMatch() method looks like:

        Query<Keyword> query = getDs()
            .createQuery(Keyword.class)
            .filter("keyword = ", "Oscar")
            .filter("score = ", 12);
        assertNull(getDs().find(PhotoWithKeywords.class)
                          .field("keywords")
                          .elemMatch(query)
                          .get());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants