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

Firestore查询报错:收到无效Payload,请求排查结构化查询问题

Firestore API查询400(INVALID_ARGUMENT)错误修复

需求

查询product_page集合中price字段等于100的文档

问题场景

使用POST请求调用Firestore API时返回400(INVALID_ARGUMENT)错误,提示:

无效JSON负载,document字段下不存在structuredQuery字段

原请求信息:

  • 请求URL:https://firestore.googleapis.com/v1/projects//databases/(default)/documents/product_page/
  • 请求体包含structuredQuery结构,但嵌套位置错误

错误原因

  1. URL路径错误:集合查询需使用Firestore的runQuery接口,路径应为:runQuery,而非直接指向集合的路径,且URL中缺失必填的项目ID。
  2. 请求体结构错误:structuredQuery是请求体的根字段,不应嵌套在document字段下。

修正后的请求示例

正确请求URL

https://firestore.googleapis.com/v1/projects/[你的项目ID]/databases/(default)/documents:runQuery

替换[你的项目ID]为实际Firebase项目ID

正确请求体(JSON)

{
  "structuredQuery": {
    "from": [
      {
        "collectionId": "product_page"
      }
    ],
    "where": {
      "fieldFilter": {
        "field": {
          "fieldPath": "price"
        },
        "op": "EQUAL",
        "value": {
          "integerValue": "100"
        }
      }
    }
  }
}

注意事项

  • 如果price是浮点数类型,将integerValue替换为doubleValue并传入对应数值(如"100.0")
  • 确保请求头中设置Content-Type: application/json

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 03:36:28