You're not telling Firebase what field to order/filter on. So what property do you want to be equal to Alex?
To tell the database this, you call orderByChild(...) before equalTo(...):
var db = admin.database();
var ref = db.ref("people");
ref.orderByChild("FirstName").equalTo("Alex").on("child_added", function(snapshot) {
console.log(snapshot.key);
});
This will work in a web client, which will just keep an open connection to the Firebase Database while the page is open. But in Cloud Functions your code will be shut down quickly, so you'll want to typically read using once("value",...):
ref.orderByChild("FirstName").equalTo("Alex").once("value", function(snapshot) {
snapshot.forEach(function(child) {
console.log(child.key);
});
});
If you run this code in Cloud Functions, you need to tell Cloud Functions when you're done. To do this, you return a so-called promise from your code. A simple way here is to do:
return ref.orderByChild("FirstName").equalTo("Alex").once("value", function(snapshot) {
snapshot.forEach(function(child) {
console.log(child.key);
});
return Promise.resolve();
});
So in the callback we return a resolved promise once we're done. And then our outer code returns that to the Cloud Functions environment, so that it knows that your code it done.