【发布时间】:2021-11-13 22:48:37
【问题描述】:
我在 App Store 上有一个 firebase 应用程序。在 firebase 的用户集合中,我有一堆字段,例如 first_name、last_name 等。我想在所有现有文档中添加另一个字段(年龄)。我怎样才能做到这一点?如果我不更新它,应用程序会给出错误,指出文档中不存在该字段。
【问题讨论】:
标签: firebase google-cloud-firestore google-cloud-functions
我在 App Store 上有一个 firebase 应用程序。在 firebase 的用户集合中,我有一堆字段,例如 first_name、last_name 等。我想在所有现有文档中添加另一个字段(年龄)。我怎样才能做到这一点?如果我不更新它,应用程序会给出错误,指出文档中不存在该字段。
【问题讨论】:
标签: firebase google-cloud-firestore google-cloud-functions
这没什么特别的:
由于您使用 Cloud Functions 进行了标记,因此在 Node.js 中这将类似于:
const usersRef = db.collection('users');
const snapshot = await usersRef.get();
await Promise.all(snapshot.docs.map(doc => doc.ref.update({age: 42})));
这是基于 Firebase 文档中的这些链接:
您可能还想看看:
【讨论】: