Listing all collections in database and sending them to express-handlebars

Viewed 7

I'm trying to get all of the collections in the database and send them over to the handlebars. My current code gets me the array of all collections, but I'm not quite sure how to get the name of it

router.get('/', isLoggedIn, async (req, res) => {

    MongoClient.connect(url).then((client) => {
        const connect = client.db(databasename);
        connect.listCollections().toArray(function (err, collections) {
        if (!err) {
            console.log(collections)        
            res.render('index', { title: 'Home', data: collections });
        }
    });
});
{{#each data}}
<a href="" class="d-flex">
   <i class="my-auto fa-regular fa-copy"></i>
    <span class="ms-2"> {{ name }}</span> 
</a>
{{/each}}

So basically, I need to get the name of all of the collections and have them in .hbs

0 Answers
Related