Firebase Database Query (AngularFire)


I am using Ionic 2 and Firebase to build a chat app.

I have the following code, that creates an entry:

import {
} from 'angularfire2';

    public af: AngularFire
        let memberIds: string[] = [senderId, receiverId];
          memberIds: memberIds,

As you can see, it adds a chat for the specified memberIds made up of a senderId and a receiverId.

The following code, returns a list of all the chats.

this.firelist ='/chat/', {
  query: {
    orderByChild: 'negativtimestamp',

Now, I want to only be able to retrieve the chats for specified memberIds.


How do I retrieve a list of chats for only a specified senderId or receiverId? i.e. The chats that contain either a matching senderId or receiverId in the memberIds.

Any help appreciated.


I add the following which is supposed to be used to add a filter:

import 'rxjs/add/operator/filter';
    this.firelist ='/chat/', {
      query: {
        orderByChild: 'negativtimestamp'
    }).filter(item => item.memberIds === 'xxx');

However, I get the following:

[ts] Property ‘filter’ does not exist on type

enter image description here


How did you solve this?


AngularFire uses its specific observable which doesn’t contains all methods of rxjs. That’s why filter() is not found.

Anyway to filter a result you need to add “equalTo” to your query object and set the field you want to search in “orderByChild”

this.firelist ='/chat/', {
  query: {
    orderByChild: 'senderId ',
    equalTo: 'yourFilterValueHere'

Check official doc for more details :