Node.js 使用nodejs报告争用错误的批更新

Node.js 使用nodejs报告争用错误的批更新,node.js,google-cloud-firestore,google-cloud-functions,Node.js,Google Cloud Firestore,Google Cloud Functions,我尝试在集合中更新,有1400多个办公室,在检查并运行查询后,我在集合文档中更新,在子集合中更新,查询后几乎没有详细信息,但有时会出现此错误 10中止:这些文档上的争用太多。请再试一次。 我只是在文档中使用批处理,这是我在集合中更新的代码 batch.set( rootCollections.x.doc(getISO8601Date()) .collection(subCollection.y) .doc(change.after.get('Id')), { of

我尝试在集合中更新,有1400多个办公室,在检查并运行查询后,我在集合文档中更新,在子集合中更新,查询后几乎没有详细信息,但有时会出现此错误 10中止:这些文档上的争用太多。请再试一次。 我只是在文档中使用批处理,这是我在集合中更新的代码

batch.set(
  rootCollections.x.doc(getISO8601Date())
    .collection(subCollection.y)
    .doc(change.after.get('Id')),
  {
    officeId: change.after.get('Id'),
    office: change.after.get('office'),
    status: change.after.get('status'),
    creationTimestamp:
      change.after.get('creationTimestamp') ||
      change.after.get('createTimestamp') ||
      change.after.get('timestamp'),
    activeUsers: [...new Set(phoneNumbers)].length,
    confirmedUers: activityCheckinSubscription.docs.length,
    uniqueActivities: [...new Set(activities)].length,
    payments: 0,
    contact: [
      `${change.after.data().creator.phoneNumber},${
        change.after.data().attachment['First Contact'].value
      }`,
    ],
  },
  { merge: true },
);
batch.set(
  rootCollections.x.doc(getISO8601Date()),
  {
    Added: admin.firestore.FieldValue.increment(1),
  },
  { merge: true },
);
PromiseArray.push(batch.commit());
await Promise.all(PromiseArray); 

在这个类似的案例中,您似乎面临着同样的问题,数据库中有数千条记录正在更新。正如这里所阐明的,您对一秒钟内可以在文档中执行多少写入操作有限制—更多详细信息—而且即使Firestore有时可能会使用更快的写入速度,它也会在某个时候失败。

由于这是硬编码的,并且是Firestore施加的限制,因此您可以尝试在类似情况下解释的解决方案,即更改为实时数据库,其中限制不是写入的数量,而是数据的大小,或者在Firestore中使用计数器或其他数据聚合,要使用分布式计数器解决方案,您可以获得更多详细信息

总而言之,除非使用此解决方案解决问题,否则您将无能为力,因为这是Firestore的一个限制