我想将新的Cloud Firestore集成到我的云功能中.
我更新了node.js并在我的mac上安装了最新的firebase版本.
文件说:
exports.myFunctionName = functions.firestore
.document('users/marie').onWrite((event) => {
// ... Your code here
});
Run Code Online (Sandbox Code Playgroud)
应该管用.我只是复制代码并将其粘贴到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)
Run Code Online (Sandbox Code Playgroud)
关于这个问题的任何建议/想法?
node.js firebase google-cloud-functions google-cloud-firestore
在Firebase的Cloud Functions中,我尝试运行admin.firestore.batch(),但收到错误“ admin.firestore.batch不是函数”,请参阅(完全简化)示例。
exports.getTest = functions.https.onRequest((request, response) => {
cors(request, response, () => {
var batch = admin.firestore.batch(); // <--- ERROR HERE
var docRef = admin.firestore().doc('tariffs/1')
batch.set(docRef, 'name', 'free');
return batch.commit();
}).then(() => {
response.status(200).send({result: 'success'});
});
});
Run Code Online (Sandbox Code Playgroud)
我的package.json是
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"cors": "^2.8.1",
"firebase-admin": "^5.4.2",
"firebase-functions": "^0.7.1"
},
"private": true
}
Run Code Online (Sandbox Code Playgroud)
是否可以在Cloud Functions中使用firebase.firestore.batch()?
谢谢
node.js firebase google-cloud-functions google-cloud-firestore