问题描述
我目前正在测试新的 firestore,但我总是遇到同样的问题,它告诉我有关 Deadline exceeded
I'm currently testing out the new firestore but I always get the same problem that it tells me something about Deadline exceeded
{ Error: Deadline Exceeded
at /user_code/node_modules/firebase-admin/node_modules/grpc/src/node/src/client.js:554:15
code: 16,
metadata: Metadata { _internal_repr: {} },
note: 'Exception occurred in retry method that was not classified as transient' }
这是我当前的代码,看起来不错(当我将它部署到 Firebase 时可以工作)
This is my current code which seems fine (and works when I deploy it to Firebase)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
var serviceAccount = require("./xxxxxxxx-firebase-adminsdk.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://xxxxxxxxx-xxxx.firebaseio.com"
});
exports.registerUser = functions.auth.user().onCreate(event => {
admin.firestore().collection('users').doc(event.data.uid).set({
name: 'Test User',
country: 'USA'
}).catch(error => {
console.log(error);
})
});
它还显示此消息函数返回未定义、预期的 Promise 或值
推荐答案
使用 Cloud Functions 触发器,您需要 返回一个承诺,该承诺在工作完成后得到解决.文档上的 set() 方法返回一个 promise,因此您应该返回它以让 Cloud Functions 知道何时可以安全地清理该函数:
With Cloud Functions triggers, you need to return a promise that becomes resolved when the work is complete. The set() method on the document return a promise, so you should return it to let Cloud Functions know when it's safe to clean up the function:
exports.registerUser = functions.auth.user().onCreate(event => {
return admin.firestore().collection('users').doc(event.data.uid).set(...)
});
这篇关于带有 Firestore 错误“已超过截止日期"的 Cloud Functions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!