How to count the number of of children for a parent in the new firebase version 9 using numChildren()?
This is how it is done in firebase version 8 below
firebase.database().ref('users/' userId).on('value', (snapData) => {
console.log(snapData.numChildren())
})
But in version 9 this isn't working below
onValue(ref(db, 'users/'), (snapData) => {
console.log(snapData.numChildren())
})
Does anyone know how it is done in firebase version 9 numChildren()?
CodePudding user response:
There is no numChildren anymore in v9, but you can get the same value with"
onValue(ref(db, 'users/'), (snapData) => {
console.log(Object.keys(snapData.val()).length) // 