I’m trying to use orderByChild to sort quizzes by newest or most played for my game. I tried:
“`javascript
var mostViewedPosts = firebase.database().ref(‘quizzes’).orderByChild(‘plays’);
console.log(mostViewedPosts)
and it logs out some random thing I don’t understand at all, and it doesn’t have any documentation as far as I could find. How do you use orderByChild!? Like how do I get the data ordered?? Thanks
EDIT: Just tried this:
“`javascript
var mostViewedPosts = firebase.database().ref(‘quizzes’).orderByChild(‘plays’);
mostViewedPosts.get().then(data => {
console.log(data.val())
})
and I get this error:
`Uncaught (in promise) Error: Index not defined, add “.indexOn”: “plays”, for path “/quizzes”, to the rules at Repo.ts:472:29
Please help!