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

$each modifier is not handled correctly in $addToSet command #846

Open
sumezulike opened this issue Jun 1, 2023 · 0 comments · May be fixed by #847
Open

$each modifier is not handled correctly in $addToSet command #846

sumezulike opened this issue Jun 1, 2023 · 0 comments · May be fixed by #847

Comments

@sumezulike
Copy link

sumezulike commented Jun 1, 2023

Using the $each modifier with $addToSet doesn't always result in unique values because of how the values of the $each are handled:

https://github.com/mongomock/mongomock/blob/ca41f27161c50d83d5ef8c899623084dd6f09a1d/mongomock/collection.py#LL704C37-L706C80

Example:

import mongomock

client = mongomock.MongoClient()
coll = client.db.coll
id = coll.insert_one({"numbers": []}).inserted_id

coll.find_one_and_update({"_id": id}, {"$addToSet": {"numbers": {"$each": [1, 1, 1, 1]}}})
print(coll.find_one({"_id": id}))

This will result in {"numbers": [1, 1, 1, 1]} instead of {"numbers": [1]}.

@sumezulike sumezulike linked a pull request Jun 1, 2023 that will close this issue
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 a pull request may close this issue.

1 participant