You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cloud Firestore runQuery在API Explorer中无法正常工作的问题

Firestore查询问题:从Demographics集合筛选指定Instructor的文档

目标

从Demographics集合中获取所有Instructor字段等于instructor2@fssi.com的文档。

API Explorer操作异常记录

parent参数格式问题

在runQuery方法的API Explorer页面,parent参数要求填写projects/{projectId}/databases/{databaseId}/documents或projects/{projectId}/databases/{databaseId}/documents/{document_path}格式,但第一种格式无法正常使用:

  • 填写projects/MYPROJECT/databases/(default)/documents时触发错误:parent does not match pattern: /^projects\/[^/]+\/databases\/[^/]+\/documents\/[^/
  • 修改为projects/MYPROJECT/databases/(default)/documents/Demographics/后问题解决,推测官方示例存在错误。

请求体构造与执行错误

通过页面按钮生成的结构化查询请求体如下:

{
  "structuredQuery": {
    "where": {
      "fieldFilter": {
        "field": {
          "fieldPath": "Instructor"
        },
        "op": "EQUAL",
        "value": {
          "stringValue": "instructor2@fssi.com"
        }
      }
    }
  }
}

执行后返回错误:

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"structuredQuery\" at 'document': Cannot find field.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "document",
            "description": "Invalid JSON payload received. Unknown name \"structuredQuery\" at 'document': Cannot find field."
          }
        ]
      }
    ]
  }
}

curl调整后成功执行

修改查询内容后,使用curl命令可成功完成查询:

$ curl -X POST "https://firestore.googleapis.com/v1/projects/MYPROJECT/databases/(default)/documents:runQuery" -H "Authorization: Bearer ACCESS-TOKEN" -H "Content-Type: application/json" --data '{
  "structuredQuery": {
    "from": [{ "collectionId": "Demographics" }], 
    "where": {
      "fieldFilter": {
        "field": {
          "fieldPath": "Instructor"
        },
        "op": "EQUAL",
        "value": {
          "stringValue": "instructor2@fssi.com"
        }
      }
    }
  }
}'

内容的提问来源于stack exchange,提问作者umair durrani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 12:34:59