【发布时间】:2017-08-21 15:44:09
【问题描述】:
我试图在写入完成后更新一个值(在云函数中),但它不起作用(我确信这是一个愚蠢的简单问题)。代码如下:
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 is the problem. Whatever I try here it won't work to retrieve the value.
//So, how to I get the "start" value, which has been written to the DB (TIMESTAMP value)?
var startValue = snapshot.ref.child('start').val();
snapshot.ref.update({ end: (startValue + 85800000) }).then(snapshot2=>{
response.redirect(303, snapshot.ref);
});
});
});
是我使用 admin.database() 的问题吗?
【问题讨论】:
标签: node.js firebase firebase-realtime-database google-cloud-functions firebase-admin