There is a JSON structure that looks like this:
{
"engagedUsers": {
"qwe": {
"agent_availability": true,
"conv_id": "parthengineer_qwe",
"emailId": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6d1c1a082d0a000c04">[email protected]</a>",
"login_time": 1512644440,
"name": "qwe",
"uid": "adasfklsfjdskldgsgjgjkl"
},
"tt": {
"agent_availability": true,
"conv_id": "genesis_tt",
"emailId": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7d3d3e7">[email protected]</a>",
"login_time": 1512644440,
"name": "tt",
"uid": "adasfklsfjdskldgsgjgjkl"
}
}
}
I am trying to check if the value of the 'conv_id' child is equal to parthengineer_qwe. However, my current code is not working as expected:
this.engagedRef = firebase.database().ref('engagedUsers');
this.engagedRef.orderByValue().once('value', function (snapshot) {
snapshot.forEach(function (data) {
if ((data.child('conv_id').val() == 'parthengineerqwe') && (existEngageduser !== 1)) {
existEngageduser = 1
}
if (existEngageduser == 1) {
isEngaged = true
}
})
return isEngaged;
});
I am looking for a better approach to achieve this, as I want the isEngaged
variable to be true. Any suggestions?