0

I'm using Firebase with Polymer 2.0. My Firebase database contains users and groups. A user can be part of more than one group. A user can have different roles in different groups.

I want to list all groups where user is a member but I cant find a way to limit the firebase query to groups where user is a member. It's listing everything or nothing.

Database structure looks like this:

 {
  "groups" : {
    "$groupId" : {
      "members" : {
        "$userId" : "true",
      },
      "name" : "Group Name A"
    },
  },
  "users" : {
    "$userId" : {
      "groups" : {
        "$groupId" : "true",
      },
      "settings" : {
        "name" : "Linus"
      }
    }
  }
}

Query looks like this:

  <firebase-auth user="{{user}}"></firebase-auth>
  <firebase-query
    id="query"
    path="/groups"
    order-by-child="members/{{user.uid}}"
    equal-to="{{user.uid}}"
    data="{{accounts}}">
  </firebase-query>

Expected result in this case would be to only display groups where $userId is true.

  • What is the value of `{{user}}`? – Ofisora Sep 06 '17 at 10:10
  • Thank you for asking @Ofisora , it made me realize it should be `{{user.uid}}`, value comes from ``. I still don't get the `equal-to=""` to work though... I've edited my question with this info. – Linus Källander Sep 06 '17 at 11:31
  • My question was what values are assigned in {{user}}? `equal-to` requires object. – Ofisora Sep 06 '17 at 11:37
  • I'm not sure how to answer your question. {{user}}-object is populated if user is logged in, through ``. `{{user.uid}}` in this example would be equal to `User_1_key`. Is that what you are asking? – Linus Källander Sep 06 '17 at 12:00
  • According to this [article](https://github.com/firebase/polymerfire/issues/75) `equal-to` should be `equal-to="true"` but I still can't get it to work... Ping @Ofisora – Linus Källander Sep 09 '17 at 09:34
  • 1
    this might be late but I think you can use the attribute start-at="{{user.uid}}" and end-at="{{user.uid}}" instead of equal-to – Rodel Nov 21 '17 at 06:48

0 Answers0