Guille Acosta Guille Acosta - 5 months ago 10
AngularJS Question

querying firebase data among all children with auth

I followed this tutorial to make an app with firebase sync and authentication. But now, I don't know how to make a query to search among all children because these children have a lexicographical-based key.

To be more specific, from this example, how do you query all "currentCity" from all "users"

{
"users" : {
"1e2f048f-a3a0-4190-afad-81d724ed1997" : {
"currentCity" : "Arrecifes",
"currentCountry" : "ARG",
"currentState" : "BSA",
"day" : {
"domingo" : true,
"jueves" : true,
"martes" : false,
"miercoles" : true
},
"gender" : "Masculino",
"name" : "Guillermo H Acosta",
"position" : "Medio",
"registered" : true,
"timeSince" : "22:00",
"timeUntil" : "23:00",
"whereToPlay" : "Güemes"
},
"39c6ccf9-61ec-446e-9af3-3a87810fab71" : {
"currentCity" : "Alvear",
"currentCountry" : "ARG",
"currentState" : "CRR",
"day" : {
"jueves" : true,
"miercoles" : true,
"viernes" : true
},
"gender" : "Masculino",
"name" : "Guillermo Acosta",
"registered" : true,
"timeSince" : "21:00",
"timeUntil" : "23:00"
},
"4991bdc9-dfc4-4ff5-ab81-0e28f1b3ab53" : {
"currentCity" : "Cordoba",
"currentCountry" : "ARG",
"currentState" : "COR",
"day" : {
"miercoles" : true,
"viernes" : true
},
"gender" : "Masculino",
"name" : "Hsjja",
"timeSince" : "02:00",
"timeUntil" : "03:00"
},
"509364fd-388b-42ff-91ed-0811811a4ff3" : {
"day" : {
"jueves" : true,
"lunes" : true,
"martes" : false,
"sabado" : true
},
"name" : "Guillermo Acosta",
"position" : "Delantero",
"timeSince" : "13:00",
"timeUntil" : "14:00",
"whereToPlay" : "Güemes"
}
}
}

Answer

With the Firebase Database, you either get a node or you don't get that node. There is no way to get a part of each nodes in a query.

So if you want load just the cities of all users, you should keep a node that contains just that information:

{
  "userCurrentCities" : {
    "1e2f048f-a3a0-4190-afad-81d724ed1997" : "Arrecifes",
    "39c6ccf9-61ec-446e-9af3-3a87810fab71" : "Alvear",
    "4991bdc9-dfc4-4ff5-ab81-0e28f1b3ab53" : "Cordoba",
  }
}