我正在尝试为 Firebase Cloud Functions 编写一个 onCall 函数,该函数在 firestore 数据库上执行高级查询任务(即根据 AutoML 自然语言检查文本查询以获取类别等),但在尝试查询来自函数的数据库:
Error getting documents :: Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/srv/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
功能:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
exports.query = functions.https.onCall((data, context) => {
const text = data.text;
var results = [];
const promise = db.collection('providers').get()
promise.then((snapshot) => {
console.log('marker');
snapshot.forEach((doc) => {
results.push({id: doc.id, data: doc.data()});
});
console.log('yessir');
return {results: results};
}).catch((err) => {
console.log('Error getting documents :: ', err)
console.log('nosir');
return {results: "no results"};
});
});
更长的输出:
Function execution started
Function execution took 8ms, finished with status code: 200
Error getting documents :: (etc, same error)
nosir
示例2(运行中没有变化):
Function execution started
Function execution took 1200 ms, finished with status code: 200
marker
yessir
我不知道这个问题从何而来或如何解决。
有什么帮助吗?
Regards.