I have a query where I am querying in a desc order using as follows
const { id } = userDetails;
const initialQuery = await firestore().collection('class')
.orderBy('createdAt', 'desc')
.where(`access.readAccess.${id}`, '==', true)
.limit(5);
initialQuery.onSnapshot((documentSnapshots) => {
const { docs } = documentSnapshots;
const lastVisible = docs.length > 0 ? docs[docs.length - 1] : '';
console.log(docs);
})
const getMore = async(store, userDetails) => {
const { id } = userDetails;
const { lastVisible } = lastState;
const initialQuery = await firestore().collection('class')
.orderBy('createdAt', 'desc')
.where(`access.readAccess.${id}`, '==', true).startAfter(lastVisible)
.limit(5);
const documentSnapshots = await initialQuery.get();
const { docs } = documentSnapshots;
}
When I do this I get an error of The query requires an index which seems fair and also helpful url to create the indexing. As I create the indexing it creates indexing of
class
access.readAccess.`1571158795762` Ascending createdAt Descending
Collection
Enabled
Now in this 1571158795762 will keep changing based on the user logged in. So, of course, it started complaining about the other user. Also, onSnapshot doest get called with desc order.
Any suggestion, please?