Cloud Functions 中的 Cloud Firestore
Cloud Firestore in Cloud Functions
我想将新的 Cloud Firestore 集成到我的 Cloud Functions 中。
我更新了 node.js 并在我的 mac 上安装了最新的 firebase 版本。
文档说:
exports.myFunctionName = functions.firestore
.document('users/marie').onWrite((event) => {
// ... Your code here
});
应该可以。我只是复制代码并将其粘贴到 index.js 中,就像所有其他实时数据库函数一样。当我部署函数代码 ($firebase deploy --only functions) 时,出现此错误:
Cannot read property 'document' of undefined
at Object.<anonymous> (/private/var/folders/zm/wp2415l929s472jv7kzbt3km0000gn/T/fbfn_21520Y4xqAJosBNHe/index.js:196:45)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
任何suggestions/ideas问题?
尝试将您的包裹更改为:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"firebase-admin": "~5.4.0",
"firebase-functions": "^0.7.0"
},
"private": true
}
然后 运行 在终端中进行更新(npm 更新)。
我完成了在新文件夹中创建全新项目的过程,它为我消除了错误。
只需调用 firebase init
即可。 (这也改变了 Package.json 文件)
好的,我尝试了所有这些方法,但没有成功。但是 firebase 进行了更新,现在可以使用了:)
好像他们有一些错误。
感谢您的帮助!
In many cases, new features and bug fixes are available only with the latest version of the Firebase CLI and firebase-functions SDK. It's a good practice to frequently update both the Firebase CLI and the SDK with these commands inside the functions folder of your Firebase project:
始终确保您使用的是更新的软件包。
npm install firebase-functions@latest --save
npm install -g firebase-tools
我想将新的 Cloud Firestore 集成到我的 Cloud Functions 中。
我更新了 node.js 并在我的 mac 上安装了最新的 firebase 版本。
文档说:
exports.myFunctionName = functions.firestore
.document('users/marie').onWrite((event) => {
// ... Your code here
});
应该可以。我只是复制代码并将其粘贴到 index.js 中,就像所有其他实时数据库函数一样。当我部署函数代码 ($firebase deploy --only functions) 时,出现此错误:
Cannot read property 'document' of undefined
at Object.<anonymous> (/private/var/folders/zm/wp2415l929s472jv7kzbt3km0000gn/T/fbfn_21520Y4xqAJosBNHe/index.js:196:45)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
任何suggestions/ideas问题?
尝试将您的包裹更改为:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"firebase-admin": "~5.4.0",
"firebase-functions": "^0.7.0"
},
"private": true
}
然后 运行 在终端中进行更新(npm 更新)。
我完成了在新文件夹中创建全新项目的过程,它为我消除了错误。
只需调用 firebase init
即可。 (这也改变了 Package.json 文件)
好的,我尝试了所有这些方法,但没有成功。但是 firebase 进行了更新,现在可以使用了:)
好像他们有一些错误。
感谢您的帮助!
In many cases, new features and bug fixes are available only with the latest version of the Firebase CLI and firebase-functions SDK. It's a good practice to frequently update both the Firebase CLI and the SDK with these commands inside the functions folder of your Firebase project:
始终确保您使用的是更新的软件包。
npm install firebase-functions@latest --save
npm install -g firebase-tools