Firestore REST API开始查询 [英] Firestore REST API starting query

查看:180
本文介绍了Firestore REST API开始查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使用Firestore REST API.数据库具有用户集合.每个用户都是单独的文档.我需要使所有用户的类别都等于1.例如,这是我的尝试(请求正文):

I am struggling with Firestore REST API. Database have a collection with Users. Every user is separate document. I need to get all users with, for example, category equal 1. Here is my attempt (request body):

{
      "structuredQuery": {
            "where" : {
                "fieldFilter" : { 
                      "field": { "fieldPath" : "category" } , 
                                 "op":"EQUAL", 
                                 "value": { "integerValue" : 1 }
                                }
                      }

      }

    }

和响应错误:

"error": {
  "code": 400,
  "message": "kind is required for filter: category",
  "status": "INVALID_ARGUMENT"
}

我完全不知道"fieldFilter"中的"field"应该是什么样子.提前致谢.

I have totaly no idea, how "field" inside "fieldFilter" should looks like. Thanks in advance.

推荐答案

我相信,如果您包含结构化查询的"from"属性,则可以使用.如果您要查询的集合称为用户",则根据您在上面发布的内容,它将看起来像这样:

I believe if you include the "from" property of the structured query, this will work. If the collection you're querying from is called "users" it would look like this, based on what you posted above:

{
    "structuredQuery": {
        "where" : {
            "fieldFilter" : { 
                "field": {"fieldPath": "category"}, 
                "op":"EQUAL", 
                "value": {"integerValue": 1}
            }
        },
        "from": [{"collectionId": "users"}]
    }
}

这篇关于Firestore REST API开始查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆