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

Mongo filter collections #334

Open
zhenyabodukhin opened this issue Oct 9, 2023 · 3 comments
Open

Mongo filter collections #334

zhenyabodukhin opened this issue Oct 9, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@zhenyabodukhin
Copy link
Contributor

Hey,

Is it possible to filter collections in Mongo using $elemMatch instead of $match?
For example:
order: {
"tasks": [
{
"name" : "first",
"priority: 5
},
{
"name" : "second",
"priority": 4
}
]
};

The filter will be: "tasks.name":"first" and "tasks.priority":4.
And this filter return this order, because "first" matches first element of array and "4" matches second element of array, but i needed to match filter for element of array, not for whole array.

@torshid torshid changed the title Turkraft filter collections in Mongo Mongo filter collections Jan 10, 2024
@torshid
Copy link
Member

torshid commented Jan 10, 2024

For the filter 'tasks.name':'first', the generated expression would be:

{ "$expr" : { "$eq" : ["$tasks.name", "first"]}}

Which will not work since tasks is a collection as you mentionned. I am not sure how to use $elemMatch here, do you have an idea?

@torshid torshid added the enhancement New feature or request label Jan 10, 2024
@torshid
Copy link
Member

torshid commented Jan 10, 2024

@zhenyabodukhin
Copy link
Contributor Author

zhenyabodukhin commented Jan 11, 2024

Hi! we have fixed this using $anyElementTrue. Here files which we patched.
TransformerUtils.txt
JsonNodeHelperImpl.txt
NotInOperationJsonNodeProcessor.txt
LikeOperationJsonNodeProcessor.txt
InOperationJsonNodeProcessor.txt

Works great. For example: tasks.name:'value' and tasks.technicalName:'value' will find documents where at least one element of tasks matches this filter.
Yes, maybe this code need refactoring, but i have not much time to fix this problem :)
And there is problem with search by date fields. This converter will fix this problem.
Norlmalize method will be :
if (field.getType().equals(LocalDateTime.class) || field.getType().equals(ZonedDateTime.class) || field.getType().equals(LocalDate.class)) {
return new ClassInfo(false, CustomDate.class);
}
ClassInfo its my class which contains info is array field or not, maybe you find better way.
DateConverter.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants