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

support for array_filters #2769

Merged
merged 17 commits into from
Jan 8, 2024
Merged

support for array_filters #2769

merged 17 commits into from
Jan 8, 2024

Conversation

idoshr
Copy link
Contributor

@idoshr idoshr commented Sep 21, 2023

Add option to user array_filters in mongoengine

idoshr and others added 9 commits December 16, 2023 19:52
Co-authored-by: Bastien Gérard <[email protected]>
Co-authored-by: Bastien Gérard <[email protected]>
Co-authored-by: Bastien Gérard <[email protected]>
Co-authored-by: Bastien Gérard <[email protected]>
Co-authored-by: Bastien Gérard <[email protected]>
Co-authored-by: Bastien Gérard <[email protected]>
…into array_filters

# Conflicts:
#	docs/changelog.rst
@bagerard
Copy link
Collaborator

bagerard commented Dec 16, 2023

Putting it in __raw__ is a bit weird as it means that __raw__ won't be a "raw" update dictionary passed as is to pymongo anymore but it would now be something that we parse because we are using it to pass custom keys.

The 2 alternatives that I see are

Document.objects
    .update(__raw__={'$set': {"tags.$[element]": 'test11111'}}).\
    .array_filters([{"element": {'$eq': 'test2'}}])

or
2)

Document.objects
    .update(__raw__={'$set': {"tags.$[element]": 'test11111'}}, array_filters=[{"element": {'$eq': 'test2'}}])

The second one seems to be slightly better in my opinion as it's not too far from the native pymongo api

collection.update_many(
    filter,
    update,
    upsert=False,
    array_filters=None,
    ...
)

What do you think?

@idoshr
Copy link
Contributor Author

idoshr commented Dec 18, 2023

@bagerard
Option 2 it is exactly what I did. May be the documentation is bit confused.
But you can look at the testers.

@bagerard
Copy link
Collaborator

bagerard commented Jan 5, 2024

@bagerard Option 2 it is exactly what I did. May be the documentation is bit confused. But you can look at the testers.

Argh indeed I misunderstood that, let me re comment it accordingly

Copy link
Collaborator

@bagerard bagerard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix latest comments and it will be good to go

@bagerard bagerard merged commit dda51bd into MongoEngine:master Jan 8, 2024
17 checks passed
@bagerard
Copy link
Collaborator

bagerard commented Jan 8, 2024

Looks good, thanks for the contribution 👍

@jeonghanjoo
Copy link

This is just what I am now looking for. 👏

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

Successfully merging this pull request may close these issues.

4 participants