首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从Firestore中的onCreate()云函数返回2个值?

从Firestore中的onCreate()云函数返回2个值?
EN

Stack Overflow用户
提问于 2021-12-29 00:14:24
回答 1查看 93关注 0票数 1

我试图从一个云函数中在不同的节点中创建以下两个文档,但不确定如何返回这两个文档。

代码语言:javascript
运行
复制
// Listen to .onCreate trigger
exports.createUserAndProfile = functions.auth.user().onCreate((user) => {

  // Create a new user (only the user themselves can access this)
  const newUser = admin.firestore().doc(`/users/${user.uid}`).set({
    announcements: [],
    email: user.email,
    onboardingSteps: ["setName", "syncStuff"],
  });

  // Create the user's public profile (any user can access this)
  const newPublicProfile = admin.firestore().doc(`/profiles/${user.uid}`).set({
    firstName: null,
    lastName: null,
    preferredName: null,
  });

  return newUser;
});
EN

回答 1

Stack Overflow用户

发布于 2021-12-29 00:18:01

如果希望在结束云函数之前完成这两种写入,则可以在Promise.all()调用中返回它们:

代码语言:javascript
运行
复制
return Promise.all(newUser, newPublicProfile);

还请参阅Promise.all的MDN文档。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70513901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档