通过REST进行Cloud Firestore子集合查询

时间:2020-01-22 17:05:56

标签: rest google-cloud-firestore

我有集合 const middlewareAPI = { getState: store.getState, dispatch: (...args) => dispatch(...args) } const chain = middlewares.map(middleware => middleware(middlewareAPI)) dispatch = compose(...chain)(store.dispatch) x的每个文档都有子集合xy的每个文档都有一个y属性。我无法弄清楚如何通过REST查询该子集合(我知道SDK中存在此功能)。到目前为止,我的查询很明显是错误的:

time

发送POST到{ "structuredQuery": { "from": [ { "collectionId": "x", "allDescendants": true } ], "where": { "compositeFilter": { "op": "AND", "filters": [ { "fieldFilter": { "field": { "fieldPath": "y.time" }, "op": "GREATER_THAN_OR_EQUAL", "value": { "integerValue": 1577836800000 } } }, { "fieldFilter": { "field": { "fieldPath": "y.time" }, "op": "LESS_THAN_OR_EQUAL", "value": { "integerValue": 1578355200000 } } } ] } } } } ,但我也尝试过https://firestore.googleapis.com/v1/projects/PROJECT/databases/{default}/documents:runQuery,但这显然也是错误的。

1 个答案:

答案 0 :(得分:1)

我相信您为集合组y描述了collection group query。在REST API中,这是对路径allDescendants(称为根文档)的projects/PROJECT/databases/(default)/documents查询:

https://firestore.googleapis.com/v1/projects/PROJECT/databases/(default)/documents:runQuery

{
  "structuredQuery": {
    "from": [
      {
        "collectionId": "y",
        "allDescendants": true
      }
    ],
    "where": {
      "compositeFilter": {
        "op": "AND",
        "filters": [
          {
            "fieldFilter": {
              "field": {
                "fieldPath": "time"
              },
              "op": "GREATER_THAN_OR_EQUAL",
              "value": {
                "integerValue": 1577836800000
              }
            }
          },
          {
            "fieldFilter": {
              "field": {
                "fieldPath": "time"
              },
              "op": "LESS_THAN_OR_EQUAL",
              "value": {
                "integerValue": 1578355200000
              }
            }
          }
        ]
      }
    }
  }
}