[英]I can not write data from the Firebase Cloud Functions in Firebase Firestore
How several days ago I started using Firebase Cloud Functions and I can not write data to the database. 几天前我开始使用Firebase Cloud Functions,但是无法将数据写入数据库。 Could you help me. 你可以帮帮我吗。 Thanks in advance. 提前致谢。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.userCreated = functions.auth.user().onCreate(event => {
let userId = event.data.uid;
let userName = event.data.displayName;
admin.firestore()
.collection("users")
.doc(userId)
.set({
name: userName,
city: "",
rating: 0
});
});
Please see the documentation to understand how Cloud Functions works with async code. 请参阅文档以了解Cloud Functions如何与异步代码一起使用。
You're not returning a promise from your function. 您不会从函数中返回承诺。 If your function performs any async work that yields a promise, you have to indicate to Cloud Functions wait for that work to complete by returning a promise that resolves when the work is complete: 如果您的函数执行任何产生承诺的异步工作,则必须通过返回一个在工作完成时可解决的承诺来指示Cloud Functions等待该工作完成:
exports.userCreated = functions.auth.user().onCreate(event => {
let userId = event.data.uid;
let userName = event.data.displayName;
return admin.firestore()
.collection("users")
.doc(userId)
.set({
name: userName,
city: "",
rating: 0
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.