I have a collection of users, which looks like this:
Each follower/following document is structured like this:
{
uid: ...,
}
I want to create a query that satisfies these criteria:
- Get the users that you are following
- Ordered by their 'lastPosted' time (so you're getting the users who have posted most recently first)
Since the follower/following subcollections only contain references to full user documents, and not the full documents themselves, it's not as easy as just querying the following subcollection.
This is what I've tried:
database
.collection('users')
.doc(myUid)
.collection('following')
.get()
.then(followings => {
database
.collection('users')
.orderBy('lastPosted', 'desc')
.where('uid', '==', following[0] || following[1] ...)
})
Which doesn't work. I have also thought about this:
database
.collection('users')
.orderBy('lastPosted', 'desc')
.where(myUid exists in their followers subcollection)
I'm not sure where to go from here, or whether firestore even allows this.