How to fetch data from mongodb and convert it to json object in node.js?

Published on Author Code Father

use toArray in mongodb client , mongodb always give json format

db.collection('demographicdetails').find().limit(10).toArray(function (err, aum) { 

aum.forEach(function (err, doc) {

        if (doc != null) {
            console.dir(doc);

        } else {
            callback();
        }
    });
})

Comments

comments