【发布时间】:2019-03-12 08:32:48
【问题描述】:
我有一个正在调用的云函数并收到此错误:不确定该怎么做?我尝试删除 return 语句并返回 Primise.all() 并返回 batch.commit(),但都失败了我还必须将 eventsRef 设为 var 而不是 const,不知道为什么。
错误:
TypeError: eventsRef.where(...).then is not a function
at exports.deleteOldEventLocations.functions.https.onRequest (/user_code/index.js:235:6)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:57:9)
at /var/tmp/worker/worker.js:689:7
at /var/tmp/worker/worker.js:673:9
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
功能:
exports.deleteOldEventLocations = functions.https.onRequest((req, res) => {
const db = admin.firestore();
var eventsRef = db.collection('events');
const currentDate = new Date();
const endDate = new Date(currentDate.getTime + 2 * 60 * 60 * 1000);
const batch = db.batch();
const fieldValue = db.FieldValue;
var query = eventsRef.where('startDate', '<', endDate)
.then(snapshot => {
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data());
let eventRef = eventsRef.doc(doc.id);
batch.update(eventRef, { g: fieldValue.delete() });
batch.update(eventRef, { l: fieldValue.delete() });
});
batch.commit();
return;
})
.catch(err => {
console.log('Error getting documents', err);
});
});
【问题讨论】:
标签: node.js firebase promise google-cloud-firestore google-cloud-functions