how to update a realtimedatabase transaction using a cloud function?

You can use ServerValue.Increment for that:

exports.updateViewCount = functions.https.onCall((data, context) => {

    const postId = data.postId;
    const userId = data.uid;
    console.log("postId: " + postId + ", userId: " + userId);

    const postsRef = admin.database().ref('posts').child(postId);



You can increment it by any numerical value atomically using that structure. Here is the documentation for more details.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top