Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firebase cloud函数在颤振中返回null,因为它';它还在跑_Javascript_Firebase_Flutter_Google Cloud Functions - Fatal编程技术网

Javascript Firebase cloud函数在颤振中返回null,因为它';它还在跑

Javascript Firebase cloud函数在颤振中返回null,因为它';它还在跑,javascript,firebase,flutter,google-cloud-functions,Javascript,Firebase,Flutter,Google Cloud Functions,更新:我正在从firebase控制台获取此信息:函数执行耗时2906毫秒,完成状态代码:200 15秒后,我得到:console.log文档确实存在 我正在运行这个云firestore功能。它“工作”,但我经常得到这个作为回报:颤振:空 但是在firebase控制台中,我得到了console.log,上面写着“DOC确实存在” 解决这个问题的办法是什么?语言打字稿 多谢各位 export const pubVer = functions.https.onCall((data, context

更新:我正在从firebase控制台获取此信息:函数执行耗时2906毫秒,完成状态代码:200 15秒后,我得到:console.log文档确实存在

我正在运行这个云firestore功能。它“工作”,但我经常得到这个作为回报:颤振:空

但是在firebase控制台中,我得到了console.log,上面写着“DOC确实存在”

解决这个问题的办法是什么?语言打字稿

多谢各位

  export const pubVer = functions.https.onCall((data, context) => {

      console.log(data.message);

      const kRef = admin.firestore().collection('Keys').doc(data.message)
      kRef.get()
        .then(doc => {
          if (!doc.exists) {
            console.log('No such document!');
            return {returnMessage: 'FALSE'}
          } else {
            console.log('DOC DOES EXIST');
            return {'returnMessage: 'TRUE'}
          }
        })
        .catch(err => {
          console.log('Error getting document', err);
        });
      });

我建议使用async/await来帮助您进行调试

export const pubVer = functions.https.onCall(async (data, context) => {
    const documentId = data.message;
    const kRef = admin.firestore().collection('Keys').doc(documentId);
    try {
        const doc = await kRef.get();
        if (!doc.exists)
            throw new Error('No such document!');
        return doc.data();
    } catch (e) {
        console.log(e);
        return null;
    }
});

可调用函数必须返回与要发送到客户端的数据解析的承诺。如图所示,函数在顶层没有返回任何内容。从
然后
回调返回是不够的。您还需要返回
返回的承诺,然后

export const pubVer = functions.https.onCall((data, context) => {

    console.log(data.message);

    const kRef = admin.firestore().collection('Keys').doc(data.message)
    return kRef.get()
        .then(doc => {
          if (!doc.exists) {
            console.log('No such document!');
            return {returnMessage: 'FALSE'}
          } else {
            console.log('DOC DOES EXIST');
            return {'returnMessage: 'TRUE'}
          }
        })
        .catch(err => {
          console.log('Error getting document', err);
        });
});

非常感谢。返回doc.data()时,我试图在firestore中设置一个新文档,其中包含用户ID和MailAddress。但当我试图实现它时:它说:“承诺必须妥善处理”@karledbedts你能分享你的全部功能吗?