我正在使用Cloud Firestore触发器
https://firebase.google.com/docs/functions/firestore-events
我的主要目标是删除一个文件;聚会;当聚会上没有人的时候。然而,我不知道如何从云火库触发器。这是我的代码:
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access Cloud Firestore.
const admin = require('firebase-admin');
admin.initializeApp();
exports.deleteOnCheckout = functions.firestore.document('/parties/{documentId}')
.onUpdate((change, context) => {
// Get an object representing the document
const newValue = change.after.data();
// ...or the previous value before this update
const previousValue = change.before.data();
// access a particular field as you would any JS property
const checkedIn = newValue.checkedIn;
console.log("Array size: " + checkedIn.length);
//If no checked in, delete document
if(checkedIn.length == 0){
return //Here I want to delete the document
}else{
//Do nothing
return null;
}
});
您尝试过作为文档引用的change.after.ref
吗?然后你可以像这个change.after.ref.delete()
那样做。