Change the JSON structure to
Electroniks:{
Macbook:{..,
Specification:{
13inch : true,
black : true
},
...
},
iPhone:{..,
Specification:{
13inch : true,
black : true,
camera : true
},
...
},
iPad:{..,
Specification:{
xinch : true,
red : true,
camera : true
},
...
}
}
, node , , , .queryEqualToValue
: - Nodes, , ,
let parentRef = FIRDatabase.database().reference().child("Elektronics")
parentRef.queryOrderedByChild("Specification/black").queryEqualToValue(true).observeSingleEventOfType(.Value, withBlock: {(snap) in
if let dict = snap.value as? [String:AnyObject]{
for each in dict{
print(each.0) //Would retrieve you every product name with colour black in specification i.e Macbook and iPhone
print((each.1["Specification"] as! NSDictionary).count)//Number of specification
parentRef.child("each.0").child("Specification").child("13inch").observeSingleEventOfType(.Value, withBlock: {(snapshot) in
if snapshot.exists(){
print(each.0) //You found your product with exactly 13inch and black Specification.This is their name
}
})
}
}else{
print(snap.ref)
}
})