In Firestore, how can you do a compound query involving a key in a map without creating an index for every key?
For example, consider a collection which holds blog posts
Now Firestore allows the array-contains
operator.
If you want to filter documents which contain specific value, try this.
First, change Map field to Array field.
Post {
title: ..
...
categories: [
cats,
puppies
]
}
Second, use array-contains
and orderBy
for each different fields.
let query = db.collection(`/posts`)
.where('categories', 'array-contains', 'cats')
.orderBy('createdAt')
.startAfter(lastDate)
.limit(5);
You can check the official document about array-contains
operator from here.