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=>{                 response.redirect(303, snapshot.ref);             });         });  }); 

is problem i'm using admin.database()?

this code:

var startvalue = snapshot.ref.child('start').val(); 

doesn't retrieve values. take @ docs datasnapshot. reach snapshot directly child() - don't need ref. maybe meant?

var startvalue = snapshot.child('start').val(); 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -