Firestore: How To Query A Map Object Inside A Collection Of Documents?
My objective:
The web app (similar to Google Drive) has 2 screens.
First screen is 'My Story' which displays all the story documents whom I'm the owner.
Second screen is 'Shared with me' which displays all the story documents that I'm either reader, writer, or commenter.
We have this /stories/{storyid}
{
title: "A Great Story",
content: "Once upon a time ...",
roles: {
alice: "owner",
bob: "reader",
david: "writer",
jane: "commenter"
// ...
}
}
Full data structure reference: https://firebase.google.com/docs/firestore/solutions/role-based-access
Question: How to write the below query to fulfil the above objective?
db
.collection('stories')
.where(`roles.${uid}`, '==', 'owner')
The above query does NOT work because it will require Firestore to index roles.alice, roles.bob, roles.david, roles.jane, and roles.[all_uid].
Edit #1: Found a related post (with no answers) asking about Firestore querying with roles
Answer
Now you can filter ...
db
.collection('orders')
.where('orderDetails.status', '==', 'OPEN')
It will check if field orderDetails at property status equals to 'OPEN'
Related Questions
- → How can I query Firebase for an equalTo boolean parameter?
- → How can I access nested data in Firebase with React?
- → Firebase simple blog (confused with security rules)
- → Removing item in Firebase with React, re-render returns item undefined
- → AngularJS Unknown Provider Error (Firebase & AngularFire)
- → How do you pass top level component state down to Routes using react-router?
- → "this" is null in firebase query function in reactjs
- → Angular Module Failed to Load
- → Multiple dex files define Lcom/google/android/gms/internal/zzrx;
- → Joining Firebase tables in React
- → How can I make add firepad to my reactjs project?
- → How to use Cloud Functions for Firebase to prerender pages for SEO?
- → React.js component has null state?