I used to have a document with the following structure:
OldDoc:
members:
['userId1', 'userId2', 'userId3']
I then wrote a query to retrieve all documents relevant to a user:
const docsSnapshot = await getDocs(query(
collection(db, 'organisations'),
where('members', 'array-contains', user.uid)
))
This worked well, but now I need to store the user's names in as well as:
members:
[{ id: 'userId1', name: 'John Smith' }, { id: 'userId2', name: 'Jane Smith' }]
The challenge I'm facing is that I'm not sure how to construct a query that would yield the same results as the first one - i.e., how do I retrieve all docs where any of the objects have an id
attribute corresponding to user.uid
.
I tried using: where('members.id', '==', user.uid)
but that didn't work.
Can a query be constructed to do this?