I have a user collection with different users, but the user have different groups A and B.
- Users (Collection)
A (Document)
- User (Collection)
- Jake (Document)
- friends (Collection)
- Justin (Document)
- Leo (Document)
- friends (Collection)
- Tom (Document)
- friends (Collection)
- Sam (Document)
- Jim 1(Document)
- friends (Collection)
- ...
- ... and so on
- Jake (Document)
- User (Collection)
B (Document)
- User (Collection)
- Justin (Document)
- friends (Collection)
- Jake (Document)
- Leo (Document)
- friends (Collection)
- Sam (Document)
- friends (Collection)
- Tom (Document)
- Jim 2(Document)
- friends (Collection)
- ...
- ... and so on
- Justin (Document)
- User (Collection)
Now I want to access the friends of group A with a collectionGroup query, because there are hundreds of users and I only want to use one request to access the friends, because of costs. Is this stupid?
When using
const query = db.collectionGroup('friends').where('name', '==', 'Tim');
museums.get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc.id, ' => ', doc.data());
});
});
I get the the Id of Jim 1 and two. But I only want to get the Id of Jim in group A.
How can I limit the access of the collectionGroup to group A.
I hope you can help me thnaks