Firebase: Filter Child Node query on Angularfire2 firebase

Asked

Viewed 68 times

1

I have this following 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 results where the vendor node with the CNPJ attribute is equal to the sent parameter.

I’m trying something like this, but I’m not getting results, returns nothing.

const rootRef = firebase.database().ref();
return rootRef.child('produtos/').orderByChild('fornecedor/cnpj').equalTo('123234534534');

1 answer

0

A quick solution is to take this list using the firebase "value" event, and use the rxjs filter operator on the client side. Another way to do it is by using firebase functionshosts to process the request on the server side and return the already processed response.

  • I understand, there is nothing simpler is it? That is solved in the orderByChild or equalto? A way to make him return the father’s records with the child as a filter?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.