I have this use case where I have to query based on the parameters sent out by the user in the form of an object. The user could send out multiple parameters to query. It is something similar to what "SELECT * FROM users WHERE FIRST_NAME = 'something' AND LAST_NAME = 'something'" is in SQL.
A sample object could be:
var object= {
email: "some...@google.com",
location: "San Jose, CA"
};
I have these fields (email & location) in my firebase data at some endpoint lets call it /users
So the users endpoint would look like:
{
"randomID1":{
email: "some...@google.com",
location: "San Jose, CA"
},
"randomID2":{
email: "anothe...@fb.com",
location: "Menlo Park, CA"
}
}
I have to use the above mentioned object and generate a query dynamically for firebase, here's what I have:
return $q(function(resolve, reject) {
ref.orderByChild("email");
for(var key in filterObject){
if(filterObject.hasOwnProperty(key)){
console.log("Key: ",key);
console.log("Value: ",filterObject[key]);
ref.equalTo(""+filterObject[key],""+key);
}
}
return ref.on("value", function (snapshot) {
resolve(snapshot.val());
}, function (errorObject) {
reject(errorObject);
});
});
This always returns me all the data and doesn't really filter anything. Can anyone provide suggestions here? I am new to firebase , sorry if this is a naive question.
Thanks