node.js - Update value once write completes in Cloud Function -
i'm trying update 1 value after write completes (in cloud function) wont work (i'm sure stupidly simple problem). code below: const functions = require('firebase-functions'); const admin = require('firebase-admin'); const firebase = require('firebase'); admin.initializeapp(functions.config().firebase); exports.createmessage = functions.https.onrequest((request, response) => { const json = json.parse(request.query.json); // == "{'start':0, 'end':0}" json.start = firebase.database.servervalue.timestamp; admin.database().ref('/messages/').push(json).then(snapshot => { //here problem. whatever try here won't work retrieve value. //so, how "start" value, has been written db (timestamp value)? var startvalue = snapshot.ref.child('start').val(); snapshot.ref.update({ end: (startvalue + 85800000) }).then(snapshot2=>{...