書き込みが完了した後(クラウド機能で)、値を更新しようとしていますが、動作しません(これは愚かな単純な問題です)。以下のコード:クラウドファンクションで書き込みが完了した時点で値を更新します
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()を使用している問題はありますか?
ありがとうございますが、これは動作しません。実際、私はスナップショットのレフェレンスではどのメソッドも使用できません。エラーログ: 'TypeError:snapshot.childは関数ではありません'。私は私の問題を "解決"しました。詳細については私の答えを見てください。 – Whyser