algolia / firestore-algolia-search

Apache License 2.0
112 stars 35 forks source link

Import script runs collection group query that does not respect collection path in config. #75

Closed iansmathew closed 3 years ago

iansmathew commented 3 years ago

Currently the retrieveDataFromFirestore function of the import script takes the last segment (the last subcollection) of the collection path and runs a collection group query on it.

This leads to documents that are not part of the config collection path being imported into Algolia. For eg: if my firestore architecture is as follows:

And if my collection path stated in the config is users/{x}/records. The import script would currently import records under both Users as well as TestUsers. This is not the expected behavior and could potentially lead to incurring unexpected costs.

Proposed Solution

Perform the collection group query as normal and then filter the results by matching the doc.ref.path to the config.collectionPath. A simple for loop (incremented by 2) matching each collection segment would let you know if the document returned is part of the collection path stated in the config and can continue with the processQuery flow.