【发布时间】:2018-11-22 10:56:51
【问题描述】:
我有一个函数来创建一个角色,该角色有 2 次写入 firestore 以创建角色并创建用户名(我创建用户名然后检查它是否已经存在,即强制使用唯一的用户名)。
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")
}
【问题讨论】:
标签: javascript firebase google-cloud-firestore