I have a node.js application that is getting a collection from MongoDB and returning it correctly. What is the simplist way I can display this information into HTML or React? I am going to be hosting this later, I tried using a MERN approach, but I feel like express was overkill as I am just trying to read the data. I also could not host the app when I used express. I do not need anything else.
const {MongoClient} = require('mongodb');
//https://www.mongodb.com/blog/post/quick-start-nodejs-mongodb--how-to-get-connected-to-your-database
//https://www.mongodb.com/blog/post/quick-start-nodejs--mongodb--how-to-read-documents
async function main(){
/**
* Connection URI. Update <username>, <password>, and <your-cluster-url> to reflect your cluster.
* See https://docs.mongodb.com/ecosystem/drivers/node/ for more details
*/
const uri = "mongodb+srv://mongodbTest:password@cluster0-bib2p.mongodb.net/test?retryWrites=true&w=majority"
const client = new MongoClient(uri);
try {
// Connect to the MongoDB cluster
await client.connect();
// Make the appropriate DB calls
await listDatabases(client);
await findOneListingByName(client, "o2");
} catch (e) {
console.error(e);
} finally {
await client.close();
}
}
main().catch(console.error);
async function listDatabases(client){
databasesList = await client.db().admin().listDatabases();
console.log("Databases:");
databasesList.databases.forEach(db => console.log(` - ${db.name}`));
};
async function findOneListingByName(client, nameOfListing) {
result = await client.db("testing").collection("testcollection").findOne({ name: nameOfListing }
);
if (result) {
console.log(`Found a listing in the collection with the name '${nameOfListing}':`);
console.log(result.data);
} else {
console.log(`No listings found with the name '${nameOfListing}'`);
}
}