Indexing unknown nodes in Firebase

梦想与她 提交于 2020-07-23 15:18:02

问题


My data structure is like this:

firebase-endpoint/updates/<location_id>/<update_id>

each location has many updates that firebase adds as "array" elements.

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"]
      }
    }
  }
}

data structure sample

{
    "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
        }
    }
}

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


回答1:


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"]
      }
    }
  }
}


来源:https://stackoverflow.com/questions/35598996/indexing-unknown-nodes-in-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!