Query data in realtime database with AngularFire in nested structures

I have the following path in the Firebase Realtime database:

/dataTables/userId/dayDate/tableID/rowWithData

The structure of rowWithData is like this:

{
    "-NLBD8PD7i5DPfdgF": {
      "name": "Demo 1",
      "rows": {
        "-NLBD8RiJeyZpnKg8iKI": {
          "lastEdit": 1676495720665,
          "name": "Data 1",
          "priority": 1
        },
        "-NLBPODZMfFFXKTFDo7p": {
          "lastEdit": 1676495720665,
          "name": "Data 2",
          "priority": 5
        }
      }
  },
  "-NLBD8PD7asdas": {
    "name": "Demo 2",
    "rows": {
      "-NLBD8RiJeyZpnKg8iKI": {
        "lastEdit": 1676495720665,
        "name": "Data 3 here",
        "priority": 1
      },
      "-NLBPODZMfFFXKTFDo7p": {
        "lastEdit": 1676495720665,
        "name": "Data 4 here",
        "priority": 5
      }
    }
  }
}

I am trying these queries – the first one returns 0:

this.angularFireDatabase
  .list(`dataTables/${this.userInfo.uid}`, ref => ref.limitToFirst(50).equalTo(`search term`))
  .snapshotChanges()
  .subscribe(data => {
    console.log("search data", data);
  })   

The second one returns all the data from the database under this path /data/userId/dayDate:

this.angularFireDatabase
  .list(`dataTables/${this.userInfo.uid}`, ref => ref.orderByChild('rows'))
  .snapshotChanges()
  .subscribe(data => {
    console.log("search data", data);
    debugger;
  }) 

When I add the .equalsTo() function with any term it returns no results.

I am trying to search in the path /data/userId for all values that are in the search term.

Here are some info but I didn’t find anything practical with my situation.

https://github.com/angular/angularfire/blob/master/docs/compat/rtdb/querying-lists.md

https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data

  • How does the dataTables/${this.userInfo.uid} in your code correlate to the JSON data you shared?

    – 

  • Sorry, the path is /dataTables/userId

    – 

Leave a Comment