【问题标题】:INVALID_ARGUMENT: cannot write more than 500 entities in a single callINVALID_ARGUMENT:一次调用不能写入超过 500 个实体
【发布时间】:2022-01-19 17:15:05
【问题描述】:

我想根据客户的要求在firestore 中存储超过 500 个文档。在将文档写入(设置)到 firebase 时,我遇到了同样的问题。经过对网络的大量研究,我创建了自己的解决方案。

希望这对你有帮助..!

【问题讨论】:

    标签: node.js google-cloud-firestore google-cloud-functions


    【解决方案1】:

    此代码用于创建 5000 条虚拟记录。

    const trailContacts = () => {
      let names = [];
      for (let index = 1; index < 5002; index++) {
        names.push({
          name: 'trail',
        });
      }
      return names
    };
    

    这是将名字存储到firebase-firestore的代码。

    let contacts = trailContacts();
    let count = Math.ceil(contacts.length/500);
    for (let index =0;  index < count; index++) {
      let splicedContacts = contacts.splice(0, 499);
      let contactsBatch = db.batch();
      splicedContacts.forEach((con) => {
        let collection = {};
        let name = con.name;
        let collectionRef = db.collection('trail');
        contactsBatch.set(collectionRef, collection);
      });
      await contactsBatch.commit();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-10
      • 2019-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多