Stack Exchange
firebase filter query not working (where in)
I am working on where in query in react but not getting filtered data.
const [message, setMessage] = useState(null);
  const [conversations, setConversations] = useState(null);
  const uid1 = 30;
  const uid2 = 31;
  useEffect(() => {
    // show chat messages
    db.collection("chat").onSnapshot((snapshot) => {
      setMessage(
        snapshot.docs.map((item) => ({
          uid1: item.data().uid1,
          uid2: item.data().uid2,
          message: item.data().message,
          id: item.id,
        }))
      );
    });
  }, []);

  useEffect(() => {
    db.collection("chat")
      .where("uid1", "in", [uid1, uid2])
      .orderBy("createdAt", "asc")
      .onSnapshot((querySnapshot) => {
        querySnapshot.forEach((doc) => {
          if (
            (doc.data().uid1 == uid1 && doc.data().uid2 == uid2) ||
            (doc.data().uid1 == uid2 && doc.data().uid2 == uid1)
          ) {
            setConversations(doc.data());
          }
        });
      });
  }, []);
  console.log({ conversations });

for reference, this is my firebase data.

also this is my index rules


What are the values of the uid1 and uid2 variables in the code you shared? Can you reproduce the problem when you use hard-coded values instead of those variables? If so, please edit your question (there's a link right under it for this purpose) to show the problem with hard-coded values, instead of variables that we can't see the value of.

as mentioned in edit , it is uid1 = 30 and uid2 = 31

So you say that inside .where("uid1", "in", [uid1, uid2]) the values are 30 and 31, right?

Running into this same exact issue. @TejendraSinghRajawat, did you ever figure this out? My only difference is that I am using .get() on the query instead of onSnapshot(), but the result is the same; records that I can see exist are not returned.
