本文介绍了带有Firestore错误“已超过最后期限"的云功能;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在测试新的 firestore ,但我总是遇到一个相同的问题,即它告诉我有关已超过最后期限

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);
  })
});

它还会显示此消息函数返回的未定义,期望的承诺或值

推荐答案

使用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错误“已超过最后期限"的云功能;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 16:52