Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
like image 536
vctlzac Avatar asked Oct 30 '25 10:10

vctlzac


2 Answers

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()});
like image 61
vctlzac Avatar answered Nov 03 '25 00:11

vctlzac


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,
         })
like image 37
Arthur Alves Avatar answered Nov 03 '25 00:11

Arthur Alves