简体   繁体   English

firebase 查询如何从子项中检索两个特定值

[英]firebase query how can i retrieve two specific values from child

i use recyclerview to retrieve a chat messages and i am wondering if there is method to retrieve two different values i mean something like this:我使用 recyclerview 检索聊天消息,我想知道是否有检索两个不同值的方法,我的意思是这样的:

FirebaseRecyclerOptions<enchat> options = 
    new FirebaseRecyclerOptions.Builder<enchat>()
        .setQuery(
            mChatDatabase.orderByChild("state").equalTo("sent")
            && mChatDatabase.orderByChild("state").equalTo("received"),
         enchat.class)
        .build();

There is no way to pass two values into a condition.无法将两个值传递给一个条件。 Firebase Realtime Database doesn't support this type of OR condition. Firebase 实时数据库不支持此类 OR 条件。

Also see:另见:

The common workarounds are:常见的解决方法是:

  • Perform two queries and merge the results in your application code.执行两个查询并将结果合并到您的应用程序代码中。 But you won't be able to use the adapters from FirebaseUI as is in that case.但是在这种情况下,您将无法使用来自 FirebaseUI 的适配器。

  • Perform a range query, but this only works if there are no state values between received and sent .执行范围查询,但这仅在receivedsent之间没有state值时有效。 If that is the case, the query could be:如果是这种情况,查询可能是:

     mChatDatabase.orderByChild("state").startAt("received").endAt("sent")
  • Add an additional property that is true when the state is either received or sent and filter on that:添加一个附加属性,该属性在receivedsent state时为真,并对其进行过滤:

     mChatDatabase.orderByChild("stateIsReceivedOrSent").equalTo(true)

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

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