I have a firebase database as described below:
"users" : {
"USER1_ID" : {
"email" : "user1@xxxx.com",
"last_connection" : "dd-mm-yyyy",
"name" : "Mr User1",
},
"USER2_ID" : {
"email" : "user2@yyyy.com",
"last_connection" : "dd-mm-yyyy",
"name" : "Mr user2"
}
}
How do I translate the following SQL query to an angular2/angularfire2 query:
SELECT COUNT(USER_ID) from USERS WHERE USER_ID = UID;
The aim of this query is to determine if a record exists. I am thinking about the below solution:
existsUser(UID: string): boolean {
this.af.database.list(`/users/${UID}`)
.subscribe ((user) => {
if (user.length == 0) {
return false;
}
});
return true;
}
Is this the fastest way to determine if a record exists?