'Converting firebase 8 code to firebase 9 code (web, javascript) to fetch collection within collection

Hello I would like to convert the following firebase 8 code to firebase 9 and have no clue how to do it - any help would be welcome!

This piece of code should go inside the userDoc and then fetch the collection that is insdie that document and return all of the posts that belong to that user

if (userDoc) {
    user = userDoc.data()
    const postsQuery = userDoc.ref
        .collection('posts')
        .where('published', '==', true)
        .orderBy('createdAt', 'desc')
        .limit(5)
    posts = (await postsQuery.get()).docs.map(postToJSON)
}

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source