So I'm trying to get single ID of a document, I tried something like this, before it worked, but since new version update it says that imported mongo
from mongodb
does not exist. This means that mongo
library doesn't longer exist, is there any other way of doing this?
So here is my following response which I want to send:
app.get ('/products/:id', async (req , res) => {
let id = req.params.id;
let db = await connect();
console.log("params: ",id);
let doc = await db.collection("posts").findOne({_id: mongo.ObjectId(id)});
console.log(doc)
res.json(doc)
});
I used this: import mongo from 'mongodb';
and when I try to get single ID from a document it says: Cannot read property 'ObjectId' of undefined
.