简体   繁体   中英

how to query key Angularfire2

How can i query the users node. i tried using

            return this.db.list('groups/', {
              query: {
                orderByChild: 'users',
                equalTo: uid
              }
            });

在此处输入图片说明

Your query is definitely not going to work. There are a few solutions that come to mind:
1 - if you have the groupUid:

groupUid = "asdasdafd";
return this.db.list('groups/'+this.groupUid+'/users', {
          query: {
            equalTo: uid
          }
        });

or something like this:

// import 'rxjs/add/operator/filter';
groupUid = "asdasdafd";
return this.db.list('groups/'+this.groupUid+'/users')
    .filter(item => item==uid);

2 - if you don't have the groupUid:
you need to receive the this.db.object('groups/') object , and after that iterate with simple loop(over all users) inside loop(over all groups) to search for uid you need.
something like:

for(var prop in groups){
  for(var j=0;j<prop.users.length;j++){
    //search the uid you need
  }
}

hope its helped you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM