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

update collection.find to support nested fields #354

Merged
merged 1 commit into from
Nov 28, 2024
Merged
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
6 changes: 5 additions & 1 deletion arango/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,9 @@ def build_filter_conditions(filters: Json) -> str:
if not filters:
return ""

conditions = [f"doc.`{k}` == {json.dumps(v)}" for k, v in filters.items()]
conditions = []
for k, v in filters.items():
field = k if "." in k else f"`{k}`"
conditions.append(f"doc.{field} == {json.dumps(v)}")

return "FILTER " + " AND ".join(conditions)
4 changes: 4 additions & 0 deletions tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,10 @@ def test_document_find(col, bad_col, docs):
col.insert({"foo bar": "baz"})
assert len(list(col.find({"foo bar": "baz"}))) == 1

# Test find by nested attribute
col.insert({"foo": {"bar": "baz"}})
assert len(list(col.find({"foo.bar": "baz"}))) == 1


def test_document_find_near(col, bad_col, docs):
col.import_bulk(docs)
Expand Down
Loading