0
push
을 사용하여 firebase 실시간 데이터베이스에 의견 양식 데이터를 쓰고 있습니다. 나는 코멘트를 붙잡기 위하여 onWrite
사건을 위해 보는 기능을 배치했다.Firebase 고유 ID에 액세스
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.newComment = functions.database.ref('{postRef}')
.onWrite(event => {
console.log("Started!");
return theComment(event.data);
});
function theComment(snapshot) {
console.log("Running theComment");
var comment = snapshot._delta;
console.log(comment);
}
반환 된 나무는 다음과 같습니다 :
가 여기 내 함수의
{ '-L10TQfRr9IFhOsd1nJe':
{ md5Email: '93942e96f5acd83e2e047ad8fe03114d',
message: 'This is a test post.',
moderated: false,
name: 'demo',
postedAt: 1514000728416 }
}
나는 key
값이 V3의 ID를 반환 할 것을 읽을 수 있지만 것 내가 comment.key
를 기록 할 때, 그것은 undefined
을 기록합니다.
새로운 요소를 작성하고 액세스 할 수있는 더 좋은 방법이 있습니까? 당신은 '그나마
다른 접근해야 사용할 수 있습니다, 개체 주석 재산라는 이름의 키가 'snapshot'의 키는 ...'snapshot.key' 또는'snapshot.ref.key'와 같습니다. – charlietfl