Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase client-side fan-out for data consistency

Tags:

firebase

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?

like image 947
Luis Cabrera Avatar asked Oct 27 '15 12:10

Luis Cabrera


1 Answers

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']);
like image 143
Frank van Puffelen Avatar answered Oct 01 '22 12:10

Frank van Puffelen