我在数据库中有一个喜欢的值,我想在喜欢超过10时更改值STATE。 这是我的数据库结构
"QUESTIONS" : {
"ENGLISH" : {
"QUESTIONID" : 1
},
"SPANISH" : {
"1" : {
"ANSWER" : true,
"LIKES" : 11,
"MADEBY" : "lScayuKFOrOWyenYYxbL3lJ8Utt1",
"QUESTION" : "djshsvs",
"SPAM" : 1,
"STATE" : "WAITING"
},
"2" : {
"ANSWER" : true,
"LIKES" : 2,
"MADEBY" : "lScayuKFOrOWyenYYxbL3lJ8Utt1",
"QUESTION" : "djdbdb",
"STATE" : "WAITING"
},
"3" : {
"ANSWER" : true,
"MADEBY" : "lScayuKFOrOWyenYYxbL3lJ8Utt1",
"MISPELLED" : 1,
"QUESTION" : "fhki",
"STATE" : "WAITING"
},
"4" : {
"ANSWER" : true,
"LIKES" : 1,
"MADEBY" : "lScayuKFOrOWyenYYxbL3lJ8Utt1",
"QUESTION" : "bkkki",
"STATE" : "WAITING"
},
"QUESTIONID" : 4
}
},
我的火力基地功能
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.newPost = functions.database
.ref('/QUESTIONS/SPANISH/{postID}'/"LIKES")
.onWrite(function(event) {
const likes=event.data.value;
const id=event.params.postID;
if(likes>10){
return event.data.ref.parent.child('STATE').set("ACEPTED");
}
return false;
});
该功能已正确部署,但除非我增加喜欢没有任何反应,我做错了什么?
答案 0 :(得分:1)
您的参考字符串看起来不正确。你有这个:
'/QUESTIONS/SPANISH/{postID}'/"LIKES"
不应该是这个吗?
'/QUESTIONS/SPANISH/{postID}/LIKES'
答案 1 :(得分:0)
除了更改参考字符串(如上所述)之外,请尝试更改此行:
const likes=event.data.value;
到这一个:
const likes=event.data.val();