亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

未能將數據發送到 Cloud Firestore

未能將數據發送到 Cloud Firestore

牛魔王的故事 2021-09-30 15:01:45
我正在嘗試將一些隨機數據推送到云 Firestore。因此,我使用帶有 - firebase init 函數的云函數初始化了項目。在函數目錄中,我有一個文件 seed.js,其中包含發送數據的代碼。使用 faker 生成數據。const faker = require("faker");const db = admin.firestore();const fakeIt = () => {  return db.collection("customers").add({    username: faker.internet.userName(),    avatar: faker.internet.avatar(),    bio: faker.hacker.phrase()  });};Array(20)  .fill(0)  .forEach(fakeIt);當我運行 node seed.js 時,我收到了下面描述的錯誤PS C:\Users\Ghost\Random Projects\Algolia\functions> node .\seed.js(node:1636) UnhandledPromiseRejectionWarning: Error: Unable to detect a Project Id in the current environment.To learn more about authentication and Google APIs, visit:https://cloud.google.com/docs/authentication/getting-started    at _getDefaultProjectIdPromise.Promise (C:\Users\Ghost\Random Projects\Algolia\functions\node_modules\google-auth-library\build\src\auth\googleauth.js:90:31)    at process._tickCallback (internal/process/next_tick.js:68:7)(node:1636) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 21)(node:1636) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.(node:1636) UnhandledPromiseRejectionWarning: Error: Unable to detect a Project Id in the current environment.To learn more about authentication and Google APIs, visit:https://cloud.google.com/docs/authentication/getting-started    at _getDefaultProjectIdPromise.Promise (C:\Users\Ghost\Random Projects\Algolia\functions\node_modules\google-auth-library\build\src\auth\googleauth.js:90:31)    at process._tickCallback (internal/process/next_tick.js:68:7)
查看完整描述

2 回答

?
有只小跳蛙

TA貢獻1824條經驗 獲得超8個贊

您需要在文件頂部初始化 firebase 應用程序


像這段代碼的東西


admin.initializeApp(Object.assign({}, functions.config().firebase, {

    credential: admin.credential.cert(serviceAccount),

}));


查看完整回答
反對 回復 2021-09-30
  • 2 回答
  • 0 關注
  • 194 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號