0

I am trying to get all users that have a certain listId in their contactLists object. My firebase realtime database structure is as follows:

user:  
  john:
     contactLists: 
       -NIOsvb: true,
     

I have other users in the DB and I want to get all that have -NIOsvb in their contactLists object. This is the approach I tried (listId is passed as a parameter):

const snapshot = await get(query(ref(db, "users"), orderByChild("contactLists"), equalTo(listId)))

I expected to get all the user objects that have this id in their contactLists. However, the value of snapshot is null. Any suggestions would be appreciated, as I don't have a lot of experience with Firebase functions.

kokiqn
  • 1
  • 1
  • Your current data structure makes it easy to find all contacts for a given user, but it does not make it easy to find all users for a given contact. For more on this, see https://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Dec 04 '22 at 00:57

0 Answers0