Javascript 云函数模拟器无法读取或写入firestore数据库
昨天我用模拟器在本地运行云函数,没有问题。重新启动后,当我回来设置我的Javascript 云函数模拟器无法读取或写入firestore数据库,javascript,firebase,google-cloud-firestore,google-cloud-functions,firebase-cli,Javascript,Firebase,Google Cloud Firestore,Google Cloud Functions,Firebase Cli,昨天我用模拟器在本地运行云函数,没有问题。重新启动后,当我回来设置我的export GOOGLE\u APPLICATION\u CREDENTIALS=时,我现在无法读取或写入数据库。我删除了我的密钥,创建了一个新密钥,但仍然遇到同样的问题。我创建了一个简单的函数,它运行时没有错误,但在模拟器中运行时不会读取或写入数据库。.get()函数表示它找不到任何内容,.set()既不返回任何内容,也不写入数据库 Edit*我的函数在部署到firebase时确实会运行,但我有一个函数可以解析和加载大量数
export GOOGLE\u APPLICATION\u CREDENTIALS=
时,我现在无法读取或写入数据库。我删除了我的密钥,创建了一个新密钥,但仍然遇到同样的问题。我创建了一个简单的函数,它运行时没有错误,但在模拟器中运行时不会读取或写入数据库。.get()
函数表示它找不到任何内容,.set()
既不返回任何内容,也不写入数据库
Edit*我的函数在部署到firebase时确实会运行,但我有一个函数可以解析和加载大量数据,由于需要多长时间,我必须在本地运行这些数据
exports.dumbFunction = functions.https.onRequest((request, response) => {
admin
.firestore()
.collection("test")
.doc("hello")
.get()
.then(function(doc) {
if (doc.exists) {
console.log("You got me" + doc.data());
} else {
console.log("I couldn't find anything");
}
});
admin
.firestore()
.collection("test")
.doc("test123")
.set({
setme: "ok",
asdf: "asdf"
})
.catch(err => {
console.log("did I error?");
console.log(err);
});
console.log("hi again");
});
我已经按照下面的说明做了
当我在第三个链接中运行node.js示例时,我得到了以下错误消息,我认为这是我的问题,但我不知道为什么或如何修复
Unknown network resource requested!
- URL: "http://metadata.google.internal./computeMetadata/v1/instance"
ERROR: Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.<anonymous> (/home/ben/Development/polity/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:168:23)
at Generator.next (<anonymous>)
at fulfilled (/home/ben/Development/polity/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:19:58)
at processTicksAndRejections (internal/process/task_queues.js:89:5)
请求未知网络资源!
-URL:“http://metadata.google.internal./computeMetadata/v1/instance"
错误:错误:无法加载默认凭据。浏览到https://cloud.google.com/docs/authentication/getting-started 了解更多信息。
在古格里斯。(/home/ben/Development/polity/functions/node_modules/google auth library/build/src/auth/googleauth.js:168:23)
在Generator.next()处
完成时(/home/ben/Development/polity/functions/node_modules/google auth library/build/src/auth/googleauth.js:19:58)
在处理和拒绝时(内部/process/task_queues.js:89:5)
当我echo$GOOGLE\u APPLICATION\u CREDENTIALS
时,它显示它被设置为包含我的密钥的JSON文件
请求的未知网络资源
是我现在在其他函数中看到的东西,这是我在它们工作时没有收到的东西
有什么想法吗
非常感谢仍然无法使此功能正常工作,但我找到了解决方法。使用nodejs的函数框架工作得很好
在admin SDK返回的承诺完全解决之前,您正在向客户端发送响应。简单地调用then和catch不会让代码等待结果。因此,我希望这个函数在很多情况下都不起作用代码>在我的示例中,我忘记删除它。即使不发送响应,它仍然不起作用。该函数只是我现在在本地运行的所有函数出现的更大问题的一个例子。请查看您的firestore规则。仿真器将默默地消化这些错误。