[英]Get data from firebase database not working
im new in firebase and im trying to get data from firebase database我是 firebase 新手,我正在尝试从 firebase 数据库中获取数据
JS Code : JS代码:
const userAnswersRef = admin.database().ref('/ChatbotProj/answers').child(userId);
return userAnswersRef.once('value')
.then((dataSnapshot1) => {
console.log("Fetching successed.");
if (!dataSnapshot1.exists()) {
return {}
}
var answers = dataSnapshot1.val();
delete answers.lastQuestionId;
return answers;
});
};
I'm trying to get answers
from the database.我正在尝试从数据库中获取
answers
。 The problem is that the code return null
when I execute dataSnapshot1.val();
问题是当我执行
dataSnapshot1.val();
时代码返回null
dataSnapshot1.val();
even though that answers
is not null
即使
answers
不为null
Can anyone help me ?谁能帮我 ? Thanks
谢谢
After answers you need to include "/", otherwise the resulting path would look like,在回答之后你需要包含“/”,否则结果路径看起来像,
/ChatbotProj/answers12345uid
instead of,代替,
/ChatbotProj/answers/12345uid
Set it like the example below,像下面的例子一样设置它,
const userAnswersRef = admin.database().ref('/ChatbotProj/answers/').child(userId);
Or, as I prefer to do it,或者,我更喜欢这样做,
const userAnswersRef = admin.database().ref("ChatbotProj").child("answers").child(userId);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.