我有一個locations-orders
表看起來像這樣:Firebase:如何爲嵌套字段添加索引?
{
"0BW3H9T3R7HJB" : {
"orders" : {
"01750ea0-4980-4bc4-58b2-988c02324e671478636582396" : {
"created_at" : 1478636560000,
},
"01750ea0-4980-4bc4-58b2-988c02324e671478636582483" : {
"created_at" : 1478636560000,
}
}
}
每個位置訂單節點有多個鍵/對象的orders
節點。這些對象上有一個created_at
字段。
我說這我的數據庫規則:
{
"rules": {
".read": true,
".write": true,
"users": {
".indexOn": "merchantId"
},
"merchants": {
".indexOn": "locations"
},
"locations-orders": {
".indexOn": ["orders/created_at"]
}
}
}
然而,火力地堡仍然抱怨說,我失去了一個索引:
Using an unspecified index. Consider adding ".indexOn": "created_at" at /locations-orders/1JS53G0TT5ZQD/orders to your security rules for better performance
我應該運行的東西創建索引?還是它寫錯了?
=== UPDATE ===
我改變了我的文件來看看:
{
"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作爲文本可以搜索,使我們能夠輕鬆地使用它來測試您的實際數據並將其用於我們的答案中,而且一般而言,這只是一件好事。 –
肯定會做! – Edmund
@FrankvanPuffelen更新! – Edmund