Javascript Firebase实时数据库-如何订阅数据库添加?
我的Firebase实时数据库中有一组笔记。 我的客户在数据库的/notes路径中订阅修改。 但当“客户机A”添加新注释时,数据不会推送到“客户机B” 我的数据库结构 我的Firebase访问规则Javascript Firebase实时数据库-如何订阅数据库添加?,javascript,firebase,firebase-realtime-database,firebase-security,Javascript,Firebase,Firebase Realtime Database,Firebase Security,我的Firebase实时数据库中有一组笔记。 我的客户在数据库的/notes路径中订阅修改。 但当“客户机A”添加新注释时,数据不会推送到“客户机B” 我的数据库结构 我的Firebase访问规则 "notes": { ".indexOn": ["data/title", "access/author"], //entry-level access ".read": " auth.uid !== null && query.equalTo ===
"notes": {
".indexOn": ["data/title", "access/author"],
//entry-level access
".read": "
auth.uid !== null && query.equalTo === auth.uid
",
"$note_id": {
".write": "
//If new data
(!data.exists() && auth.uid !== null) ||
(
data.child('access').child('author').val() === auth.uid
||
data.child('access/members').child(auth.uid).exists()
)
",
"data": {
//access
".read": "
//if author or assigned user
data.parent().child('access').child('author').val() === auth.uid ||
data.parent().child('access/members').child(auth.uid).exists()
"
}
}
}
上述访问规则旨在防止客户端读取所有“注释”
但是,由“客户A”创建的“客户B”有权访问的新便笺决不会推送到“客户B”。如果“客户端B”重新加载应用程序,则会出现新的注释,但这与订阅的目的背道而驰
如何确保添加到/notes节点的内容在访问规则就绪的情况下推送到我的客户机上?上述代码有效。问题出在
调度(setnotes(notes))
中。
我不小心做了一些额外的检查,但没有将所有注释传递给数组。:/因此,我向存储发送了错误的数据。发送正确的updatednotes
解决了问题/K
"notes": {
".indexOn": ["data/title", "access/author"],
//entry-level access
".read": "
auth.uid !== null && query.equalTo === auth.uid
",
"$note_id": {
".write": "
//If new data
(!data.exists() && auth.uid !== null) ||
(
data.child('access').child('author').val() === auth.uid
||
data.child('access/members').child(auth.uid).exists()
)
",
"data": {
//access
".read": "
//if author or assigned user
data.parent().child('access').child('author').val() === auth.uid ||
data.parent().child('access/members').child(auth.uid).exists()
"
}
}
}