0

I am trying to filter data from Firebase realtime database by child value But i am not able to do as it was simple to do in web version 8 How can i achieve

i tried below

get(ref(database, 'Orders/'), orderByChild('status').equalTo('onTheWay')).then((snapshot) =>{
   //my code here
});

it gives me the following error

orderByChild(...).equalTo is not a function

enter image description here

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84

1 Answers1

2

You need to use query() function to build a query and pass each clause as a separate argument in it instead of chaining them. Try refactoring your code as shown below:

import { getDatabase, get, ref, query, orderByChild, equalTo } from "firebase/database";

const q = query(ref(db, 'Orders/'), orderByChild('status'), equalTo('onTheWay'));

get(q).then(snapshot => {
  console.log(q)
})
Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
  • Thanks for the Solution. I got the Rules error that i fixed by the following solution https://stackoverflow.com/questions/53295841/the-proper-way-of-adding-an-index-in-a-nested-firebase-realtime-database-structu – Kashif Nazeer Dec 28 '21 at 16:53