我在firebase上有这样的数据结构
-B4PWzQ84KUOeuTuxVY:{
doctorId:2,
Message:abc
}
我想基于StudentId检索消息,所以记录太多 我的代码只检索整个对象,但只要DoctorId为2,我只需要Messages值
db.ref('students/' )
.orderByChild("DoctorId")
.equalTo("2")
.once('value',(whereresult) => {
var message = whereresult.val();
});
答案 0 :(得分:2)
代码中存在三个问题:
doctorId
<> DoctorId
。equalTo
。总计:
db.ref('students/' )
.orderByChild("doctorId")
.equalTo(2)
.once('value',(snapshot) => {
snapshot.forEach(function(child) {
console.log(child.key, child.val());
});
});