【发布时间】:2017-03-23 13:15:24
【问题描述】:
我有一个locations-orders 表,如下所示:
{
"0BW3H9T3R7HJB" : {
"orders" : {
"01750ea0-4980-4bc4-58b2-988c02324e671478636582396" : {
"created_at" : 1478636560000,
},
"01750ea0-4980-4bc4-58b2-988c02324e671478636582483" : {
"created_at" : 1478636560000,
}
}
}
每个 location-orders 节点都有一个 orders 节点,其中包含多个键/对象。这些对象上有一个created_at 字段。
我将此添加到我的数据库规则中:
{
"rules": {
".read": true,
".write": true,
"users": {
".indexOn": "merchantId"
},
"merchants": {
".indexOn": "locations"
},
"locations-orders": {
".indexOn": ["orders/created_at"]
}
}
}
但是,Firebase 仍然抱怨我缺少索引:
Using an unspecified index. Consider adding ".indexOn": "created_at" at /locations-orders/1JS53G0TT5ZQD/orders to your security rules for better performance
我应该运行一些东西来创建索引吗?还是写错了?
=== 更新 ===
我更改了我的文件以查看:
{
"rules": {
".read": true,
".write": true,
"users": {
".indexOn": "merchantId"
},
"merchants": {
".indexOn": "locations"
},
"locations-orders": {
"$location_id": {
".indexOn": ["orders/created_at", "orders/status_updated_at"]
}
}
}
}
但我仍然收到相同的警告:
Using an unspecified index. Consider adding ".indexOn": "created_at" at /locations-orders/1JS53G0TT5ZQD/orders to your security rules for better performance
【问题讨论】:
-
您在问题中包含了 JSON 树和规则的图片。请将这些替换为实际的 JSON 和文本规则,您可以通过单击 Firebase 数据库控制台中的导出按钮轻松获取这些内容。将 JSON 作为文本使其可搜索,让我们可以轻松地使用它来测试您的实际数据并在我们的答案中使用它,一般来说这只是一件好事。
-
肯定会的!!!
-
@FrankvanPuffelen 更新!
标签: firebase firebase-realtime-database firebase-security