【发布时间】:2021-05-08 22:45:51
【问题描述】:
我有一个具有以下规则的数据库:
{
"rules": {
"users": {
".read": "auth.uid != null",
".indexOn": ["time", "timestamp"],
"$uid": {
".write": "$uid === auth.uid",
}
}
}
}
和数据格式
users
|_ uid
|_ time
|_ timestamp
当我使用 once() 执行查询(使用 Cloud Functions)时,它工作得非常好
await admin.database().ref("users").orderByChild("timestamp")
.once("value", (snapshot) => {
snapshot.forEach((childSnapshot) => {
functions.logger.log(childSnapshot.key);
});
});
但是当我使用get() 执行查询时
await admin.database().ref("users").orderByChild("timestamp")
.get()
.then((snapshot) => {
snapshot.forEach((childSnapshot) => {
functions.logger.log(childSnapshot.key);
});
});
我收到以下错误:
错误:在 IndexMap.get 中没有为时间戳定义索引
请注意,根本没有定义索引时,这不是同一个错误 - 在这种情况下,错误看起来像这样:
错误:索引未定义,为路径“/users”添加“.indexOn”:“timestamp”
我在定义索引后添加了新条目,所以所有数据都应该被索引(理论上)。当然我可以只使用once(),但现在我不知道我的数据是否真的被索引了。有人能解释一下吗?
【问题讨论】:
标签: node.js firebase-realtime-database firebase-admin