Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138192

How to index firebase data for query based on dynamic keys?

$
0
0

I am trying to add a querry where I have two array-contains, which turned out not gonna work as firebase doesn't support.

const initialQuery = Firebase.firestore.collection('class')
    .orderBy('createdAt', 'desc')
    .where('access.readAccess.classrooms', 'array-contains', id)
    .where('keywords', 'array-contains', keyword)
    .limit(5);

So I ended up writing something like below.

const initialQuery = firebase.firestore().collection('class')
    .orderBy('createdAt', 'desc')
    .where(`accessibleUsers.${id}.hasAccessTo.classrooms.read`, '==', true)
    .where('keywords', 'array-contains', keyword)
    .limit(5);

Now the issue goes while trying to index this data I see the index is happing only for a particular id. And after seeing a few answers in StackOverflow I am bit confused with the whole indexing. Based on this, Indexing unknown nodes in Firebase is it saying remove the .where(accessibleUsers.${id}.hasAccessTo.class.read, '==', true) and add a rule to firebase scurity rules to read only where he has access to? How do I fix this? Any help is appreciated.


Viewing all articles
Browse latest Browse all 138192

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>