I'm using GCP with node 16 and firestore. I'm getting data of subcollection and update by id. In console.log(subCollect.id); and console.log(subCollect.data()); the information logged is correct. In update command I receive the folowing error
 var subCollecPromises = [];
 var parentPromises = [];
 var querySnapshot = await db.collectionGroup("mysubcollection")
 .where('name', '==', "subname")
 .where('sequence', '==', 2).get();
querySnapshot.forEach(doc => {
  var data = doc.data();
  if(data.enable){
    var childRef;
    var parentRef;
    childRef = doc.ref.parent;
    parentRef = childRef.parent;
    subCollecPromises.push(doc.ref.get());
    parentPromises.push(parentRef.get());
  }
});
const arrsubCollecSnap = await Promise.all(subCollecPromises);
const arrsubParentSnap = await Promise.all(parentPromises);
for (let index = 0; index < arrsubParentSnap.length; index++) {
  const item = arrsubParentSnap[index];
  var parentData = item.data();
  var subCollect = arrsubCollecSnap[index];
  console.log(subCollect.id);
  console.log(subCollect.data());
  await db.collection("mysubcollection").doc(subCollect.id)
  .update({sequence: 3, datetime: new Date()});
  await sendMail(parentData.mail);
}
Error in update:
Error: 5 NOT_FOUND: no entity to update: app: "dev~myapp-backend"
path <
  Element {
    type: "mysubcollection"
    name: "Vuxx2Hy9xprtm7tZFyne"
  }
>
    code: 5,
  details: 'no entity to update: app: "dev~myapp-backend"\n' +
    'path <\n' +
    '  Element {\n' +
    '    type: "mysubcollection"\n' +
    '    name: "Vuxx2Hy9xprtm7tZFyne"\n' +
    '  }\n' +
    '>\n',
  metadata: Metadata {
    internalRepr: Map(1) { 'content-type' => [Array] },
    options: {}
  },
  note: 'Exception occurred in retry method that was not classified as transient'
                The correct way for update a subcollection is starts at parent collection:
await db.collection("parentCollection").doc(parentId).collection("mysubcollection").doc(subCollect.id).update({sequence: 3, datetime: new Date()});
                        I was able to solve this issue by adding my database id to getFirestore() as getFirestore(<database_id>). Maybe this is the answer you are looking for.
Example:
await getFirestore(<database_id>).collection('users').doc(<doc_id>).create({
          email: email,
          name: name,
          phone: phone,
         })
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With