firebase / firebase/firebase-admin-python

Querying Firestore documents by nested key-value in an array field using Python

未关闭
#781 1 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看
api: firestore type: feature request
主要语言
Python
星标
1.2k
派生
359
平均合并
5 天 6 分钟
30 天内合并 PR
2

描述

**Is your feature request related to a problem? Please describe.**
I'm working with Firestore in Python and have a data query challenge I'm hoping to get some advice on.

My documents in Firestore are structured as follows:
```python
{
"key1": "value1",
"key2": {
"subKey1": [
{
"arrayKey1": "arrayValue1",
"arrayKey2": "arrayValue2"
},
{
"arrayKey3": "arrayValue3",
"arrayKey4": "arrayValue4"
}
],
"subKey2": "subValue2"
}
}
```

My goal is to query documents where the value of arrayKey1 within the subKey1 array matches a specific value (for example, target_arrayValue1), regardless of the arrayKey2 in the same dictionary.

Here's an example of what my query currently looks like:
```python
docs = query.where(
filter=FieldFilter(
"key2.subKey1",
"array_contains",
{
"arrayKey1": "target_arrayValue1",
"arrayKey2": "arrayValue2"
}
)
).stream()
```

This approach, however, requires a full match of the dictionary, which is not ideal.

**Describe the solution you'd like**
My “ideal” code would do something like this:

```python
docs = query.where(
filter=FieldFilter(
"key2.subKey1.0.arrayKey1",
"==",
"target_arrayValue1"
)
).stream()
```

Is there an appropriate way to structure my query to achieve this? Any insights or examples would be greatly appreciated! Thanks in advance.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。