How to check if Firebase Query Returns more than 1 Record?

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to check if Firebase Query Returns more than 1 Record?



It seems firebase Query doesn't have methods for returned results count. but, I need to perform some data operation based on returned results.


var queryRef=database.child("Family").orderByChild("age").limitToFirst(2)

queryRef.addListenerForSingleValueEvent(object : ValueEventListener
{
override fun onDataChange(p0: DataSnapshot) {
if(p0.exists()){
// do something
}
}

override fun onCancelled(p0: DatabaseError) {
}

})



but, similarly, I want p0.resultsCount instead of po.exists(). Help, me If any way it is possible to figure out returned results count.





in onDataChange(p0: DataSnapshot) { if (DataSnapshot.exists() && DataSnapshot.getChildrenCount() > 1) }
– Vadim Eksler
4 mins ago




onDataChange(p0: DataSnapshot) { if (DataSnapshot.exists() && DataSnapshot.getChildrenCount() > 1) }




1 Answer
1



You can count the number of children to which a Firebase Reference is pointing using the below method.


getChildrenCount()



For you it would be p0.getChildrenCount()


p0.getChildrenCount()






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

CG7aCT PdceJzZBvr M FsCQEL795aWSevCWEBg
kdOB4p0jUc

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results