I'm trying to delete a field document with multi-path location with the firestore batch method. I used to do it with the update method on Real Time Database. Now I don't really know how to do it on Firestore.
deleteVenueFromEvent(event)
{
var eventkey = event.$key;
var venuekey = event.venue.venuekey;
var batch = this.afs.firestore.batch();
var eventRef = this.eventCollection.doc(eventkey).ref;
batch.update(eventRef, { venue: null });
var deleteVenueRef = this.venueCollection.doc(venuekey).collection('events').doc(eventkey).ref;
batch.delete(deleteVenueRef);
batch.commit().then(function() {console.log('Batch Delete')});
}
I find the way to do it with the following code :
var deleteVenueRef = this.venueCollection.doc(venuekey).ref;
batch.update(deleteVenueRef, {['events.' + eventkey] :firebase.firestore.FieldValue.delete()});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.