Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

javascript - Firebase - IN query not working in where clause getting blank array as result

When I try to filter my data with IN query it's not showing me the result I am getting a blank array in result I have tried the same thing in the firebase console. I am not getting result there as well.

My data is messages/01fjubNOf8oYODitr1h6 In this path, I have keys - name, message, participants

{
  name: "Pawan arora",
  message: "test",
  participants: ["33", "127"]
},
{
  name: "TEST NAME",
  message: "not working",
  participants: ["114", "127"]
}
{
  name: "TEST DATA",
  message: "new",
  participants: ["114", "33"]
}

I tried in the query to filter data my query is

.collection("messages").where("participants", "in", ["33", "127"])

Here I should get the first object as a result

Firebase database image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to use array-contains-any operator instead when filtering arrays.

Try this:

.collection("messages").where("participants", "array-contains-any", ["33", "127"])

For details check this blogpost.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...