I expect to only get results where account_id = 1005 and survey_id=205244 and answers.type=12 and answers.answer=2
However, this returns results with 2 but also the results with 1 as answer.
I’m at it for a few hours now and I just don’t have any explanation why this happens.
your filter specifies all documents where account_id is 1005, survey_id is 205244 and there is at least one answer with type property equals to 12 and at least one answer with the answer property equals to 2
Hi @Rafael_Green and @steevej , thank you for your quick reply. If I understand you correctly steevej, I first do the query and then filter it out with elemMatch? If yes, is there another way that doesn’t filter after getting a lot of results but already filters it when doing the query?
I found this on StackOverflow, mongodb - elemMatch query does not work in php - Stack Overflow, see the answer, is that what you are talking about?
Thanks!
I found the solution, the last query was the right one, but i had to remove the answers. so only type and answer is left. Thank you so much for pointing me the right way!