Or clause in firebase Java Android

Who knows how I can make a common "or" in the where clause in firebase?

I need to do this in the query because I send the query to the adapter. So, I mean, I can't add a listener and check one value and then another. I need to point to the full query of the result in the query

What I have is:

chat1:
   user1Id: "1"
   user2Id: "2"
   bothUsers: "1_2"

chat2:
   user1Id: "2"
   user2Id: "4"
   bothUsers: "2_4"

I need to get all chats of the user with ID "2". I'm trying to query as follows:

userLogged = 2;
Query queryRef = firebase.orderByChild("user2Id").equalTo(userLogged);

However, when user 2 is in user2id, it will only get chat. But in the above example, when user 2 is in user1id (chat2), it will not get it. I need to get it. How can I do this?

resolvent:

In NoSQL database, you usually need to model the data according to the needs of the application (see this article for a detailed description of NoSQL data modeling). Therefore, if you need all chat lists of a specific user, please store the list:

/userChats
  user1Id
    chat1: true
  user2Id
    chat1: true
    chat2: true
  user4Id
    chat2: true

This process is called informalization, which is covered in the article linked above in firebase documentation on structuring data and blog post

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>