Search code examples
javascriptfirebasegoogle-cloud-firestoreangularfire2

firestore Check if id exists against an array of ids


I developing a simple chat applicaiton for my website using firebase firestore. where every chat session has an id

provided i have an array of ids

chat_sessions = ["q93XhadA9QQLu6X8yfZB", "YXEYISEI8b2iixCcP3VO", "GXrSZbtrmN5NcrtvjFYp"]

I want to get all document whose id is equal to any of the id's in the chat_sessions object using the code below.

return this.afs
    .collection('chats', ref => ref.where('uid','in_array',chat_sessions)).snapshotChanges...

but I am not getting any results.

I come from a PHP/MYSQL background the PHP equivalent of what i am trying to achieve will be sth like this in PHP

if(in_array(uid,chat_sessions)){
      get(doc/uid)
      }

can anyone help with the right query where we check for document id against a list of ids in an array? Thank You!


Solution

  • I found something else on firestore i.e "array-contains-any" for this case.

    Maybe it's updated now.

    Firestore condition