云功能模拟器无法读取或写入 firestore 数据库
cloud functions emulator cannot read or write to firestore database
我昨天 运行使用模拟器在本地运行我的云功能没有问题。当我回来并在重新启动后设置 export GOOGLE_APPLICATION_CREDENTIALS=
时,我现在无法读取或写入数据库。我删除了我的密钥,创建了一个新密钥,但我仍然 运行 遇到同样的问题。我创建了一个简单的函数,运行 没有错误,但在模拟器中 运行 时它不会读取或写入数据库。 .get()
函数说它找不到任何东西,.set()
没有 return 任何东西,也没有写入数据库。
编辑*我的函数在部署到 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");
});
我已按照以下说明进行操作。
https://cloud.google.com/docs/authentication/getting-started
https://firebase.google.com/docs/functions/local-emulator
https://cloud.google.com/storage/docs/reference/libraries
当我 运行 第三个 link 中的 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)
当我 echo $GOOGLE_APPLICATION_CREDENTIALS
时,它显示它已设置为包含我的密钥的 JSON 文件。
Unknown network resource requested!
是我现在在其他功能上看到的东西,这是我在工作时没有收到的东西。
有什么想法吗?
非常感谢
仍然无法正常工作,但我找到了解决方法。使用 nodejs 的函数框架工作得很好。
https://github.com/GoogleCloudPlatform/functions-framework-nodejs
我昨天 运行使用模拟器在本地运行我的云功能没有问题。当我回来并在重新启动后设置 export GOOGLE_APPLICATION_CREDENTIALS=
时,我现在无法读取或写入数据库。我删除了我的密钥,创建了一个新密钥,但我仍然 运行 遇到同样的问题。我创建了一个简单的函数,运行 没有错误,但在模拟器中 运行 时它不会读取或写入数据库。 .get()
函数说它找不到任何东西,.set()
没有 return 任何东西,也没有写入数据库。
编辑*我的函数在部署到 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");
});
我已按照以下说明进行操作。
https://cloud.google.com/docs/authentication/getting-started
https://firebase.google.com/docs/functions/local-emulator
https://cloud.google.com/storage/docs/reference/libraries
当我 运行 第三个 link 中的 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)
当我 echo $GOOGLE_APPLICATION_CREDENTIALS
时,它显示它已设置为包含我的密钥的 JSON 文件。
Unknown network resource requested!
是我现在在其他功能上看到的东西,这是我在工作时没有收到的东西。
有什么想法吗?
非常感谢
仍然无法正常工作,但我找到了解决方法。使用 nodejs 的函数框架工作得很好。
https://github.com/GoogleCloudPlatform/functions-framework-nodejs