8000 Fix matching whole array when using $in operator by hazard595 · Pull Request #917 · mongomock/mongomock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix matching whole array when using $in operator #917

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ When submitting a PR, please make sure that:
3. The code is auto-formatted (``hatch fmt``).
4. The build passes on your PR.

To download, setup and perfom tests, run the following commands on Mac / Linux:
To download, setup and perform tests, run the following commands on Mac / Linux:

.. code-block:: console

Expand Down
2 changes: 1 addition & 1 deletion mongomock/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def _in_op(doc_val, search_val):
doc_val = _force_list(doc_val)
is_regex_list = [isinstance(x, _RE_TYPES) for x in search_val]
if not any(is_regex_list):
return any(x in search_val for x in doc_val)
return any(x in search_val for x in doc_val) or doc_val in search_val
for x, is_regex in zip(search_val, is_regex_list):
if (is_regex and _regex(doc_val, x)) or (x in doc_val):
return True
Expand Down
1 change: 1 addition & 0 deletions tests/test__mongomock.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ def test__find_non_empty_array_field(self):
self.cmp.compare.find({'array_field': [['abc']]})
self.cmp.compare.find({'array_field': 'def'})
self.cmp.compare.find({'array_field': ['def']})
self.cmp.compare.find({'array_field': {'$in': [['def'], [['abc']]]}})

def test__find_by_objectid_in_list(self):
# See #79
Expand Down
0