怎么写.indexOn?

时间:2017-09-04 16:11:34

标签: android firebase

如何在Firebase和Android代码示例中编写.indexOn (问题 - > PushId - >喜欢 - > UserUID)

{
"Question" : {
  "-Kt6vXlTii19eBkKa4Wr" : {
    "Likes" : {
      "bEYW6usk5rNo5WT1tdkiBZIv1TN2" : true,
      "20Wioh8McfOeZWnn3dfVsRlQ25M2" : true
    },
    "answer_count" : 0,
    "description" : "ds",
    "image" : "aa",
    "sender_uid" : "bEYW6usk5rNo5WT1tdkiBZIv1TN2",
    "time" : 1504445344214
  }
},
"Users" : {
  "20Wioh8McfOeZWnn3dfVsRlQ25M2" : {
    "image" : "image",
    "mail" : "mail",
    "name" : "image"
  },
  "bEYW6usk5rNo5WT1tdkiBZIv1TN2" : {
   "image" : "image",
    "mail" : "mail",
    "name" : "image"
  }
}
}

这是我的规则但不起作用

  {
    "rules": {
        "Question": {
          ".read": "auth != null",
          ".write": "auth != null",
          ".indexOn": ["sender_uid","Likes"],
        },
      "Users": {
         ".read": "auth != null",
        "$uid": {
          ".write": "$uid === auth.uid",

        }
      }
    }
  }

1 个答案:

答案 0 :(得分:1)

这是解决方案

{
"rules": {
    "Question": {
      ".read": "auth != null",
      ".write": "auth != null",
      ".indexOn": ["sender_uid","Likes/value"],

      }
    ,
  "Users": {
     ".read": "auth != null",
    "$uid": {
      ".write": "$uid === auth.uid",

    }
  }
}

}