I want to select data from Firebase to match user id and notification_type, but I can’t apply multiple child. How can I do for this. I am trying with this code:
<script type="text/javascript"> var CountNotification = firebase.database().ref('notification/').orderByChild('fk_user_id').equalTo('<?php echo $this->session->userdata("user_id"); ?>'); CountNotification.on('value', function(snapshot) { var data=snapshot.val(); var i=0; Object.keys(data).forEach(function(k) { i++; }); alert(i); }); </script>
I want to count data where user_id equalTo=’some value’ and notification_type equalTo=’unread’
There have no option to use multiple orderByChild in Firebase. You can follow this code if you wan to count data to check user_id equalTo=’some value’ and notification_type equalTo=’unread’
<script type="text/javascript"> var CountNotification = firebase.database().ref('notification/').orderByChild('fk_user_id').equalTo('<?php echo $this->session->userdata("user_id"); ?>'); CountNotification.on('value', function(snapshot) { var data=snapshot.val(); var i=0; Object.keys(data).forEach(function(k) { if(data[k]['notification_type']=='unread'){ i++; } }); alert(i); }); </script>
Hope it will be helpful for you.
Question and answer is powered by AnsPress.io