Luis Cabrera
Luis Cabrera

Reputation: 569

Firebase client-side fan-out for data consistency

From the blow post below

Firebase client-side fan-out for data consistency

Multi-path updates sound awesome. Does that work the same for Multi-path deletes?

Use case: I add a new post and it is fanned-out to many many followers. I decide to delete the post later on. Does the delete work the same? Do you have an example?

Upvotes: 5

Views: 757

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599726

You can delete many posts in a single operation, by setting the value for each key to null.

function deletePostFromFollowers(postId, followers) {
    var updates = {};
    followers.forEach(function(followerId) {
        updates['/users/'+followerId+'/posts/+'postId] = null
    });
    ref.update(updates);
}
deletePostFromFollowers('-K18713678adads', ['uid1', 'uid2']);

Upvotes: 8

Related Questions