Cloud Firestore-动态查询 [英] Cloud Firestore - Dynamic Querying

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

问题描述

我在Cloud Firestore中有一个 Collection ,其中包含一定数量的项目,我们称其为 Collection "X".此项目数将不断变化.在任何给定的时间,我想侦听此 Collection 中的项目数,并在 Query 对象上创建几个 whereEqualto()调用,基于另一个集合",我们称其为"Y":

I have a Collection in Cloud Firestore that has a certain number of items, let's call it Collection "X". This number of items will constantly be changing. At any given time, I want to listen for the number of items in this Collection and create several whereEqualto() calls on a Query object that is based on another 'Collection', let's call it "Y":

Query queryStore = FirebaseFirestore.getInstance()
            .collection("Y")
            .whereEqualTo(USER_ID_LABEL,  "item 1 from X")
            .whereEqualTo(USER_ID_LABEL,  "item 2 from X")
            .whereEqualTo(USER_ID_LABEL,  "item 3 from X");
            //Could be more than 3, could be less than 3, constantly changing

基本上, whereEqualTo()的数量将是动态的.

Essentially, the number of whereEqualTo() will be dynamic.

这种类型的查询可能吗?

Is this type of query possible?

推荐答案

是. whereEqualTo()返回

Yes. whereEqualTo() returns a Query object, which can be used to build up the final query you need. There's no obligation to chain the methods all at once, as you've demonstrated in your question. What you've written is equivalent to this:

Query queryStore = FirebaseFirestore.getInstance().collection("Y")
queryStore = queryStore.whereEqualTo(USER_ID_LABEL,  "item 1 from X");
queryStore = queryStore.whereEqualTo(USER_ID_LABEL,  "item 2 from X");
queryStore = queryStore.whereEqualTo(USER_ID_LABEL,  "item 3 from X");

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

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