Node.js 使用云Firestore更新触发器删除Firestore中的文档
我正在使用云Firestore触发器。Node.js 使用云Firestore更新触发器删除Firestore中的文档,node.js,google-cloud-firestore,google-cloud-functions,Node.js,Google Cloud Firestore,Google Cloud Functions,我正在使用云Firestore触发器。 我的主要目标是删除一个文档“party” 当聚会上没有人时。然而,我不知道如何从一开始就做到这一点 云存储触发器。这是我的密码: // The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers. const functions = require('firebase-functions'); // The Firebase Admin SDK to
我的主要目标是删除一个文档“party” 当聚会上没有人时。然而,我不知道如何从一开始就做到这一点 云存储触发器。这是我的密码:
// 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;
}
});
您是否尝试过
更改.after.ref
哪个是文档引用?然后您可以这样做change.after.ref.delete()
您是否尝试过change.after.ref
哪个是文档引用?然后您可以这样做change.after.ref.delete()
。对不起,如果我错过了什么。天哪,我很确定我已经试过了。再试一次,它成功了。请写下来作为答复,我会接受的。