How to filter by orderByChild containing a string in Firebase query-based rules

浪子不回头ぞ 提交于 2019-12-24 02:56:08

问题


I want to get all the users that are friends of the logged user. This is my data structure.

{
  "users": {
    "UID1":{
        "name":"Pepito",
        "friends":{
            "UID2":true,
            "UID4":true,
        }
     }
     ...
  }
}

I am getting the users with this code

Firebase.database.reference().child("users")
        .orderByChild("friends/" + Firebase.user.uid).equalTo(true)

And the rules should be

{
  "rules": {
    "users" : {
      ".read" : "query.orderByChild.contains('friends/')",
      "$uid" : {
            ".write": "auth.uid == $uid",
      }
    }
  }
}

But the rules not working, I am getting this error when I try to save

Error saving rules – Line 6: Invalid property access: target is not an object.

The line 6 is

".read" : "query.orderByChild.contains('friends/')",

I also tried with

".read" : "query.orderByChild == 'friends/'+auth.uid",

来源:https://stackoverflow.com/questions/50887130/how-to-filter-by-orderbychild-containing-a-string-in-firebase-query-based-rules

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