You should bear in mind that Firebase is a database similar to the databases of Key Value as Redis, so the way in which you store the information depends a lot on the way you are going to access it.
Firebase does not expose an API to query SQL language in relational databases, so if you want to find a data by ID, you must embed the ID in the 'Key' or path (path) of the object.
So if you want to access clients, for example, by region, province and city, you must create 3 data structures.
FIREBASE.child('clientes').child('provincia').child(idProvincia).on("value", loadedByProvinciaCallback);
FIREBASE.child('clientes').child('ciudad').child(idCiudad).on("value", loadedByCiudadCallback);
FIREBASE.child('clientes').child('region').child(idRegion).on("value", loadedByRegionCallback);
Here I note that I use a child root called 'clients' within this child created 3 childs that for my way of accessing the information serve me as 3 contexts within 'client', a context for province, one for city and another for region, in this way I define my way of accessing the information.
You will say that this breaks principles when duplicating information, and this is fine this is not a relational database is a NoSQL database and the most important thing in Firebase is that it is a real-time database, to perform this type of databases in real time and scalable as Firebase are complex, now you can use transactions at the moment of agreagr a new client in your database to add it in the 3 contexts (region, province, city) in this way ensure that the information be consistent.
In your case you are doing a linear search within an array stored in a Firebase ref, you must take into account that this type of search has a terrible performance so if the array is very large then you will have a serious problem of latency.
Finally, once you have found the snapshot according to your search criteria, you must obtain the reference of this in order to modify it, the snapshot provides the function snapshot.ref (), which returns the reference to said snapshot.
function(snapshot){
var datos = snapshot.val();
for(var i =0; i< datos.length; i++){
if(datos[i].idCiudad == ciudad){ // aqui filtras el snapshot a editar
console.log(datos[i]);
var refModifcar = snapshot.ref(); // obtienes el ref del snapshot a editar
refModifcar.set({...}); // aqui editas el snapshot
}
}
}
Firebase documentation on how to manipulate the information.
Firebase read and write