在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'});
});
});
我的包.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
}
是否可以将 firebase.firestore.batch() 与 Cloud Functions 一起使用?
谢谢
您在admin.firestore
之后缺少()
。
更改此设置:
var batch = admin.firestore.batch(); // <--- ERROR HERE
对此:
var batch = admin.firestore().batch();