我试图从一个云函数中在不同的节点中创建以下两个文档,但不确定如何返回这两个文档。
// 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;
});
发布于 2021-12-29 00:18:01
如果希望在结束云函数之前完成这两种写入,则可以在Promise.all()
调用中返回它们:
return Promise.all(newUser, newPublicProfile);
还请参阅Promise.all
的MDN文档。
https://stackoverflow.com/questions/70513901
复制相似问题