Is there a way to retrieve and display all documents from MongoDB by creating a function that establishes a connection to the client and retrieves values? I attempted to use the toArray
method, but unfortunately, the ID does not show up in the response when I test it on Postman.
database.js
exports.getFromDb = (uri) => {
MongoClient.connect(uri, (err, db) => {
if (err) throw err;
var dbo = db.db("ToDoList");
var documents = dbo.collection("ToDo").find({});})}
index.js
app.get("/", (req, res) => {
return res.json(getFromDb(uri))
});