Looking for advice on best practices when query'ing (or options) when looking for data within a child node.
Scenario: A car lot with cars. In FB we store the car info and some specs about that car.
assume that parkingSpace0Key will always have a Chevy Camaro parked in that space but the specs may change (color, miles, sunroof, engine size, etc) so that node will be dynamic and can be a vary'ing list (so we store it in a child node)
Suppose we want to print out all green cars.
in iOS one option is to read in the entire lot node, and iterate over the read in cars and as we come across a green one, print it out.
[lotRef observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
for (FDataSnapshot* child in snapshot.children) {
NSDictionary *dict = child.value;
NSDictionary *specs = [dict valueForKey:@"specs"];
NSString *color = [specs valueForKey:@"color"];
if ( [color isEqualToString:@"green"] ) {
NSLog(@"The car in space %@ is green", child.key);
}
}
}];
Query option?
We can query on items immediately beneath the parkingSpace node, in this case looking for Chevy
FQuery *orderedByQuery = [lotRef queryOrderedByChild:@"make"];
FQuery *emailQuery = [orderedByQuery queryEqualToValue:@"Chevy"];
[emailQuery observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
NSLog(@"%@",snapshot.value);
}];
Is there a way to query on child nodes to query for green cars?
Is this a situation where flattening the data is the better option?
What are the performance issues with reading in a bunch of data* and iterating over it vs some kind of sub-query returning only the data we are interested in?
*lot could be 0-100 cars, 100-1000 cars, or 1000+ cars