My firestore has below data
/users/<id>/cards/<card-id>
/users/<id>/holdings/<card-id>/<date>/<data>
I can get all card ids with /users/<id>/cards/<card-id>
, but I can not get the same info from /users/<id>/holdings/<card-id>
const existing_card_ids = new Set();
try {
const docRef = db.collection("users").doc(userId);
const collections = await docRef.listCollections();
if (collections.length == 0) {
return existing_card_ids;
}
for (const collectionRef of collections) {
if (collectionRef.id == "cards") { // <-- NOTICE this line
const docs = await collectionRef.get();
docs.forEach((doc) => {
existing_card_ids.add(doc.id);
});
break;
}
}
} catch (error) {
console.log(error);
}
return existing_card_ids;
check the highlighted line, If I check the collection id is “holdings”, then the same code will not work.
I searched many different ways in SO and also asked Gemini, Chatgpt. Anyone knows why this is failing?