javascript - 使用firebase中的where子句检索数据
问题描述
尝试使用 firebase 数据库存储消息。在使用参考消息检索数据时,我得到了所有消息。
firebase.database().ref('messages').on('child_added', function (snapshot{
console.log(snapshot.val()
}
如何向其添加过滤器以仅接收该特定用户发送的消息。我需要我提供的用户 ID 发送和接收的消息
解决方案
您需要执行一个查询:
firebase.database().ref('messages').orderByChild("user").equalTo("john").on('value', ((snapshot) =>{
console.log(snapshot.val());
}
假设您有以下数据库:
messages
id
user : john
message : message_here
推荐阅读
- javascript - 重写后输入JS绑定函数不运行
- ios - SIGABRT:前提条件失败:导入的节点在其值被读取之前被删除
- c# - 如何使用 c# 通过 api 在linkedin 上发帖?
- excel - 如果单元格值包含部分文本,则为 MsgBox
- oracle - OracleForms - 尽管存在数据库错误,但在 key_commit 中 form_success 变为 true
- python - 在训练神经网络期间是否应该更改嵌入层?
- cassandra - Cassandra 地图中最多可以添加哪些项目?
- c# - 将扩展与 BenchmarkDotNet 进行比较
- java - 如何修复:评估 SpringEL 表达式的异常
- postgresql - 是否有类似 group by 的东西也允许我查询每个组中的各个行?