firebase - 使用 Rest Call 查询 Firebase
问题描述
我正在关注 Json。有人可以帮助我如何根据 Rate 字段过滤我的查询。我正在编写以下查询,但它不起作用
{
"documents": [
{
"name": "0C45nDuozgQDOwEx5xHR",
"fields": {
"Clinic": {
"stringValue": "American Hospital"
},
"Rate": {
"stringValue": "140"
},
,`enter code here`
"createTime": "2020-06-28T20:32:18.776123Z",
"updateTime": "2020-07-22T21:19:24.061647Z"
},
{
"name": "Jm3tNVWmk4Q1pk87KL1m",
"fields": {
"Clinic": {
"stringValue": "Cleaveland clinic"
},
"Rate": {
"stringValue": "150"
},
"createTime": "2020-06-28T20:28:03.726819Z",
"updateTime": "2020-07-22T21:19:05.073019Z"
}
}
解决方案
问题是该Rate
字段是一个对象(在另一个对象中使情况变得更糟),因此为了实现这一点,您需要更新 Firestore 结构以在请求 URL 中完成所有操作,或者您必须使用请求正文中的结构化查询。
- 改变结构:
为了处理您已有的请求,您需要将结构更改为(以第一个文档为例):
{
"name": "0C45nDuozgQDOwEx5xHR",
"Clinic": "American Hospital",
"Rate": "140",
"createTime": "2020-06-28T20:32:18.776123Z",
"updateTime": "2020-07-22T21:19:24.061647Z"
}
尽管我没有全貌,但我认为这使它更简单
- 在您的请求正文中有一个结构化查询:
为了保持你已经拥有的结构,你需要使用这个 URL:
https://firestore.googleapis.com/v1/projects/myproject/databases/(default)/documents/:runQuery
并将其添加到请求的正文中:
"structuredQuery": {
"from": [{
"collectionId": "mycollection"
}],
"where": {
"fieldFilter": {
"fields": {
"Rate": {
"stringValue": "15"
}
}
}
}
}
您可以通过查看runQuery 文档和结构化查询文档来查看更多详细信息,以了解您可以使用这些选项做些什么。
推荐阅读
- python - 在这种情况下排序值不排序?
- python - 如何使用 Pandas 通过索引获取两个 csv 之间的差异
- c - C 中的服务器套接字,带有“\n”的错误
- powershell-4.0 - Get-ChildItem 在脚本中不返回任何项目,但从命令行工作
- android - 从 Workmanager 更新 UI
- php - 如何使用重定向 html 创建 htaccess 并从 url 的最后一个获取参数
- .htaccess - CS 购物车重写供应商 URL
- r - ggplot 或 R 中的算术运算和标记
- javascript - 图表js不同的回调标签
- python - 具有固定种子的 scipy.sparse.linalg.eigsh