I'd like to do a collection group query but within a certain path, meaning that I would like to target collections not only with the collectionId but also with where the collection is.
Let's use the example used in the doc to explain it better. We would have landmarks in cities and "general" landmarks in their own collection :
let citiesRef = db.collection('cities');
let landmarks = Promise.all([
citiesRef.doc('SF').collection('landmarks').doc().set({
name: 'Golden Gate Bridge',
type: 'bridge'
}),
citiesRef.doc('SF').collection('landmarks').doc().set({
name: 'Legion of Honor',
type: 'museum'
}),
citiesRef.doc('LA').collection('landmarks').doc().set({
name: 'Griffith Park',
type: 'park'
}),
citiesRef.doc('LA').collection('landmarks').doc().set({
name: 'The Getty',
type: 'museum'
}),
citiesRef.doc('DC').collection('landmarks').doc().set({
name: 'Lincoln Memorial',
type: 'memorial'
})
]);
let generalLandmarks = Promise.all([
db.collection('landmarks').doc().set({
name: 'National Air and Space Museum',
type: 'museum'
}),
db.collection('landmarks').doc().set({
name: 'Ueno Park',
type: 'park'
}),
db.collection('landmarks').doc().set({
name: 'National Museum of Nature and Science',
type: 'museum'
}),
db.collection('landmarks').doc().set({
name: 'Jingshan Park',
type: 'park'
}),
db.collection('landmarks').doc().set({
name: 'Beijing Ancient Observatory',
type: 'museum'
})
]);
Now I would like to query for landmarks that are in a city and not get the general ones. In a simpler way, I would like to do something like this :
let museums = db.collection('cities').collectionGroup('landmarks').where('type', '==', 'museum');
Is it possible ?