Node.js firebase函数检索数据
我在firebase上有这样的数据结构Node.js firebase函数检索数据,node.js,firebase,firebase-realtime-database,Node.js,Firebase,Firebase Realtime Database,我在firebase上有这样的数据结构 -B4PWzQ84KUOeuTuxVY:{ doctorId:2, Message:abc } 我想在StudentId的基础上检索消息,因为有这么多记录 我的代码只检索整个对象,但我只需要doctorId为2的消息值 db.ref('students/' ) .orderByChild("DoctorId") .equalTo("2") .once('value',(whereresult) =&
-B4PWzQ84KUOeuTuxVY:{
doctorId:2,
Message:abc
}
我想在StudentId的基础上检索消息,因为有这么多记录
我的代码只检索整个对象,但我只需要doctorId为2的消息值
db.ref('students/' )
.orderByChild("DoctorId")
.equalTo("2")
.once('value',(whereresult) => {
var message = whereresult.val();
});
代码中有三个问题:
doctorId
doctorId
equalTo
db.ref('students/' )
.orderByChild("doctorId")
.equalTo(2)
.once('value',(snapshot) => {
snapshot.forEach(function(child) {
console.log(child.key, child.val());
});
});
代码中的DoctorId应该是带小写字母的DoctorId,并且值应该是一个数字。所以
db.ref('students/').orderByChild(“doctorId”).equalTo(2).once('value',(whereresult)=>{var message=whereresult.val();