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:
Users
Records
TestUsers
Records
Admin
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.
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 bothUsers
as well asTestUsers
. 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 theconfig.collectionPath
. A simplefor
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 theprocessQuery
flow.