Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.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 使用云函数HTTP触发器从Firestore检索数据_Javascript_Node.js_Google Cloud Firestore_Google Cloud Functions - Fatal编程技术网

Javascript 使用云函数HTTP触发器从Firestore检索数据

Javascript 使用云函数HTTP触发器从Firestore检索数据,javascript,node.js,google-cloud-firestore,google-cloud-functions,Javascript,Node.js,Google Cloud Firestore,Google Cloud Functions,我的代码在db.collection(“OrderId”).doc(“D9XjS3efiV12epxQcgYA”).get()之前工作正常。然后,因为当我取消对行的注释时,它返回“firestoreFunc runnig”,但不进行日志记录,并且在db.collection(“OrderId”).doc(“D9XjS3efiV12epxQcgYA”).get()内不返回任何内容。然后 如何使用HTTP触发器访问Firestore const functions = require('fireba

我的代码在
db.collection(“OrderId”).doc(“D9XjS3efiV12epxQcgYA”).get()之前工作正常。然后
,因为当我取消对行的注释时,它返回“firestoreFunc runnig”,但不进行日志记录,并且在
db.collection(“OrderId”).doc(“D9XjS3efiV12epxQcgYA”).get()内不返回任何内容。然后

如何使用HTTP触发器访问Firestore

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();

exports.firestoreFunc = functions.https.onCall((data, context) =>  {
    //return "firestoreFunc running";
    db.collection("OrderId").doc("D9XjS3efiV12epxQcgYA").get().then(snapshot =>  {

        console.log("log : 22");

        return 22;
    }).catch(reason =>  {

    })
});

函数必须返回一个承诺,该承诺与要发送给客户端的数据进行解析。如图所示,函数不返回任何内容,文档提取可能不会完成,因为函数将终止,因为它不知道如何等待提取

只需从get()返回的承诺中添加一个返回:


从你写的东西我无法确切地说出你打算如何处理你拿到的文件。您的可调用函数不会向客户机返回任何内容(从这里显示的内容)。如果您确实希望基于fetch文档返回某些内容,则需要正确处理承诺(您不在这里-函数将在文档可用之前返回)。您实际上想要完成什么?我正在尝试从文档中的字段“groupId”获取数据。我以为它会返回22(用于测试)。你能解释一下为什么函数在文档可用之前返回吗?
return db.collection("OrderId").doc("D9XjS3efiV12epxQcgYA").get().then(snapshot =>  {
    console.log("log : 22");
    return 22;
}).catch(reason =>  {
    // you should handle errors here
})