在Firebase中索引未知节点 [英] Indexing unknown nodes in Firebase
问题描述
我的数据结构是这样的:
My data structure is like this:
firebase-endpoint/updates/<location_id>/<update_id>
每个位置都有许多更新,firebase将这些更新添加为数组"元素.
each location has many updates that firebase adds as "array" elements.
如果在插入数据库之前未知location_id,如何在每个更新的"validFrom"属性上建立索引?
How can I index on the "validFrom" property of each update if the location_id is unknown before insertion into the databse?
{
"rules": {
"updates": {
"<location_id>": { // WHAT IS THIS NODE SUPPOSED TO BE?
".indexOn": ["validFrom"]
}
}
}
}
数据结构示例
{
"71a57e17cbfd0f524680221b9896d88c5ab400b3": {
"-KBHwULMDZ4EL_B48-if": {
"place_id": "71a57e17cbfd0f524680221b9896d88c5ab400b3",
"name": "Gymbox Bank",
"statusValueId": 2,
"update_id": "NOT_SET",
"user_id": "7017a0f5-04a7-498c-9ccd-c547728deffb",
"validFrom": 1456311760554,
"votes": 1
}
},
"d9a02ab407543155d86b84901c69797cb534ac17": {
"-KBHgPkz_buv7DzOFHbD": {
"place_id": "d9a02ab407543155d86b84901c69797cb534ac17",
"name": "The Ivy Chelsea Garden",
"update_id": "NOT_SET",
"user_id": "7017a0f5-04a7-498c-9ccd-c547728deffb",
"validFrom": 1456307547374,
"votes": 0
}
}
}
更新:我不认为这是对上述问题的重复,因为该问题也没有具有未知ID的父对象.即<location_id>
和<update_id>
都是自由格式键,不能手动设置
Update: I don't think this is a dupe of the said question becauase that question doesn't have a parent object with an unknown id as well. ie both <location_id>
and <update_id>
are free form keys and cannot be set by hand
推荐答案
我在文档中做了更多的挖掘工作,我认为这应该可行:
I did a bit more digging in the docs and I think this should work:
{
"rules": {
"updates": {
"$location_id": { // $location_id should act like a wild card
".indexOn": ["validFrom"]
}
}
}
}
这篇关于在Firebase中索引未知节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!