flutter - Flutter firestore,如何获取包含数组内值的文档
问题描述
我有一个 json 数据存储在 firestore 中,如下所示,文档的 id 是 ddmmyyyy 格式的日期
29032019:{
morning:[{
person : 1,
name:'abc',
cancelled:false
},
{
person : 2,
name:'abc',
cancelled:false
}
],
afternoon:[{
person : 3,
name:'abc',
cancelled:false
},
{
person : 4,
name:'abc',
cancelled:false
}
]
}
30032019:{
morning:[{
person : 5,
name:'abc',
cancelled:false
},
{
person : 2,
name:'abc',
cancelled:false
}
],
afternoon:[{
person : 6,
name:'abc',
cancelled:false
},
{
person : 7,
name:'abc',
cancelled:false
}
]
}
这里 9032019 和 30032019 是文档 ID。如何获取包含上午和下午数组中的人的文档,到目前为止,我可以做的是通过使用接下来的 3 个即将到来的日期来获取文档并遍历上午和下午数组以检查 ID 为 6 的人是否存在于收藏与否。
解决方案
使用 Firestore,您无法像现在那样在数组中搜索对象的字段。您只能按项目的确切内容搜索数组。
This means you will have to bring the values to search into a new field that is searchable. If you a searching by the person
field, you could create a new array field in the document called people
that contains only the integers of each person, then use an arrayContains query to find them.
推荐阅读
- google-cloud-platform - Google Compute Engine:启动脚本未在容器优化操作系统中运行
- javascript - 地图中的顺序 axios 请求
- google-cloud-platform - 从带有 GPU 的机器映像创建不带 GPU 的 GCP 实例
- vba - 什么是使用访问 vba 的最佳事件
- python - Python字符串出现计数正则表达式性能
- json - 如何从 Ionic 3 中的 JSON 对象获取不是 URL 的图标值
- python - 无法在 x86 docker 上安装 python for arm
- amazon-web-services - 如何在自动缩放组中使用更新/新的 AMI
- php - 当用户在 PHP 中注册 WordPress 时,如何创建自定义用户角色?
- mysql - MySQL:是否可以创建一个查询来评估来自不同记录的数据?