google-cloud-platformgoogle-cloud-firestoregoogle-cloud-functions

Firestore exception occurred in retry method that was not classified as transient


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'

Solution

  • 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()});