Firebase Security Rules: .indexOn unique ids

前端 未结 1 1571
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-08 19:49

I have this structure:

\"post\": {
   \"groupMember\": {
     \"-KHFHEHFWDB1213\": \"true\",
     \"-KSJHDDJISIS011\": \"true\",
     \"-KJSIO19229129k\": \"tru         


        
相关标签:
1条回答
  • 2021-02-08 20:14

    To query whether or not one of the given keys has value "true" (note that as typed your data structure is a string, not a boolean -- something to look out for!) you'll want to create security rules like so:

    {
      "post": {
        "groupMember": {
          "$memberId": {".indexOn": ".value"}
        }
      }
    }
    

    And then use queryOrderedByValue("true") on the /post/groupMember path. Important to note is $memberId in the rules, which declares a wildcard key representing your autogenerated ids, and .value, which indicates that rather than indexing on a child property (if your structure had another layer of nesting) you want to index on the immediate leaf node value.

    0 讨论(0)
提交回复
热议问题