简体   繁体   English

是否可以将 REST API“浅”功能与 Firebase 数据过滤查询参数一起使用?

[英]Is it possible to use the REST API "shallow" feature with Firebase data filtering query parameters?

The documentation ( https://firebase.google.com/docs/database/rest/retrieve-data ) for using REST to retrieve Firebase data explicitly states that 'shallow cannot be used with any of the "filtering data" query parameters'.使用 REST 检索 Firebase 数据的文档 ( https://firebase.google.com/docs/database/rest/retrieve-data ) 明确指出“shallow 不能与任何“过滤数据”查询参数一起使用”。 Here I am told that it is possible to run a shallow query with filters (eg limitToFirst, startAfter). 在这里我被告知可以使用过滤器(例如limitToFirst、startAfter)运行浅查询。

Running this:运行这个:

import firebase_admin
from firebase_admin import credentials
from firebase_admin import db

databaseReference = db.reference("/")

snapshot = databaseReference.child("Bot Applications").order_by_child("status").equal_to("ACTIVE").limit_to_first(self.applicationKeyCollectionCount).get(etag=False, shallow=True)

or或者

snapshot = databaseReference.child("Bot Applications").order_by_key().limit_to_first(self.applicationKeyCollectionCount).get(etag=False, shallow=True)

or any other simplified variation of this query results in an error message like或此查询的任何其他简化变体都会导致错误消息,例如

AttributeError: 'Query' object has no attribute 'shallow'

or或者

TypeError: get() got an unexpected keyword argument 'shallow'

or或者

TypeError: get() got an unexpected keyword argument 'etag'

The code runs successfully when the query has all filters removed like当查询删除所有过滤器时,代码成功运行,例如

snapshot = databaseReference.child("Bot Applications").get(etag=False, shallow=True)

or without the shallow feature like或者没有像

snapshot = databaseReference.child("Bot Applications").order_by_child("status").equal_to("ACTIVE").limit_to_first(self.applicationKeyCollectionCount).get()

Is there an efficient way to somehow run a shallow FRTDB query with filters?有没有一种有效的方法来以某种方式运行带有过滤器的浅 FRTDB 查询?

As far as I know the REST API can filter on the data that it returns.据我所知,REST API 可以过滤它返回的数据。 So if you request a shallow result set, it can filter on keys only.所以如果你请求一个浅的结果集,它只能过滤键。 That's also exactly what I do in the examples in my answer that you linked.这也正是我在您链接的答案中的示例中所做的。

There is no way to do a shallow query and then filter on any of the properties under the keys that are returned.没有办法进行浅查询,然后对返回的键下的任何属性进行过滤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM