0

I am using nodejs to create firestore documents in the following structure (CollectionName)/(id)/(document) and all though my code is successfully adding the document, it is not actually creating the parent document (id) if it does not already exist.

Firebase is reporting the following:

This document does not exist, it will not appear in queries or snapshots

and this is correct, i can not see a list of (id)'s when querying the database. Below is my code, how can i fix it?

for (let i = 0; i < filledOrders.length; i++) {
    let query_new_open = await db.collection("OpenOrder").doc(id).collection(filledOrders[i]._who).get();
    if (query_new_open.docs.length > 0) {
        await db.collection("OpenOrder").doc(id).collection(`${filledOrders[i]._who}`).doc(filledOrders[i]._priceInWei + "_" + filledOrders[i]._orderKey).delete();
        await update_orderBook(filledOrders[i], false);
    }
}
if (orders.length > 0) {
    for (let i = 0; i < orders.length; i++) {
        await db.collection("OpenOrder").doc(id).collection(`${orders[i]._who}`).doc(orders[i]._priceInWei + "_" + orders[i]._orderKey).set(orders[i]);
        await update_orderBook(orders[i], true);
    }
}

1 Answers1

0

Firestore does not create parent documents when a subcollection is written to. That is the expected behavior. If you want the parent document to exist, you will have to write code to make that happen. You can see in the console that a parent document does not exist because its name of that document will be in italics.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441