代码之家  ›  专栏  ›  技术社区  ›  Ilja

找出哪个firestore批处理操作失败,以及哪些数据写入了数据库?

  •  1
  • Ilja  · 技术社区  · 7 年前

    try {
      const characterPrivateRef = firestore().doc(`characters/${uid}`);
      const usernameRef = firestore().doc(`usernames/${username}`);
      firestore().batch().batch.create(characterRef, {...characterData});
      firestore().batch().batch.create(characterPrivateRef, {...usernameData});
    
      await firestore().batch().commit();
      // How can I get data written to each firestore document from batch 
      here?
    } catch (e) {
    
      // How can I check what batch failed here i.e. if it was username I 
      want to show error saying something like ("Username already exists")
    }
    
    1 回复  |  直到 7 年前
        1
  •  3
  •   Alex Mamo    7 年前