Firebase: Filter child node query on AngularFire2 firebase

1

I have this structure:

{
  "3" : {
    "data" : "2017-09-21",
    "fornecedor" : {
      "cnpj" : "123234534534",
      "fantasia" : "Barreirinha"
    },
    "nNF" : 3,
    "peso" : 3,
    "precoCompra" : 6,
    "vendido" : false
  },
  "123" : {
    "data" : "2017-09-14",
    "fornecedor" : {
      "cnpj" : "123234534534",
      "fantasia" : "Barreirinha"
    },
    "nNF" : 123,
    "peso" : 23000,
    "precoCompra" : 2.21,
    "vendido" : false
  }
}

I need to filter this list with only the results where the provider node with the CNPJ attribute is equal to the parameter sent.

I'm trying something like this, but I'm not getting results, it does not return anything.

const rootRef = firebase.database().ref();
return rootRef.child('produtos/').orderByChild('fornecedor/cnpj').equalTo('123234534534');
    
asked by anonymous 21.06.2018 / 17:27

1 answer

0

One quick fix is to get this list using the firebase "value" event, and use the rxjs filter operator on the client side. Another way to do this is to use the firebase functions to process the server-side request and return the already processed response.

    
21.06.2018 / 17:47