skip to Main Content

How to create a database object using MongoDB with Next.js?

I followed this tutorial to set up MongoDB in my Next.js application: https://www.mongodb.com/developer/languages/javascript/nextjs-with-mongodb. In a file called mongodb-config.js, I have import { MongoClient } from 'mongodb' const uri = process.env.MONGODB_URI const options = { useUnifiedTopology: true, useNewUrlParser: true, } let…

VIEW QUESTION

Mongodb – Model.findOne() is returning null

Model.findOne() is returning null even if the valid collection is present in the respective Model app.post("/fleetManagement", (req, res) => { const requestedDriverID = req.body.driverId; console.log(requestedDriverID); Driver.findOne({ _id: requestedDriverID }, function(err, requestedDriverResult) { console.log(requestedDriverResult); res.render("fleetManagement", { reqDriver: requestedDriverResult }); }); })…

VIEW QUESTION
Back To Top
Search