The Firebase data structure looks like this:
-users
--demo1
---conid:1
-election
--election1
---conRegex:1
--election2
---conRegex:1
Here is the code to retrieve election1 and election2:
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);
}
Currently, the issue is that electionArr is empty. How can I resolve this problem?