Firebase data is as follows
-users
--demo1
---conid:1
-election
--election1
---conRegex:1
--election2
---conRegex:1
the code to retrieve election1, election2 is
var conid;
var conRegex;
var electionArr = [];
if(uidAnonymous != null) {
db.ref('users/'+user).once('value', function(snapshot) {
if(snapshot.exists()) {
conid = snapshot.val().conid;
}
});
db.ref('election/').once('value', function(snapshot) {
snapshot.forEach(function(electionSnapshot) {
conRegex = electionSnapshot.val().conRegex;
if(conid.startsWith(conRegex)) {
electionArr.push(electionSnapshot.key.toString());
}
});
});
console.log(electionArr);
}
Problem is electionArr is empty? How do i solve the issue