0

I have the below scenarioenter image description here

Attempting the below fails:

  this._directChatsRef = this.db.list(`users/${this.authProvider.getUID()}/chat`, {
    query: {
      orderByChild: 'read',
      equalTo: false
    }
  });
  this._directChatsRef.subscribe((directChats) => {
    this._chats = directChats.length;
  });

I know there's an object right above the chat object, but how can I return just the array of chat objects from firebase with the specified query?

The purpose of this is to get a count of unread messages.

Thanks!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user1027620
  • 2,745
  • 5
  • 37
  • 65
  • Firebase Database queries can only order on properties at a *known path* under each node of the location where you run the query. It seems like your current structure does not meet that requirement. See also https://stackoverflow.com/questions/27207059/firebase-query-double-nested – Frank van Puffelen Dec 16 '17 at 15:19
  • Downloading all unread messages to show their count is rather wasteful of the user's bandwidth. If your app has the need to show the number of unread messages, I'd recommend keeping that precise property in your database. – Frank van Puffelen Dec 16 '17 at 15:20

0 Answers0