I am trying to find a record in my mongo db by its id
No matter I use findbyid(), findone(id,...), it return null
here is my code. what is the solution?
Convert the string into ObjectId type before querying
var ObjectID = require('mongodb').ObjectID; async function updateData(id){ const result = await Data.findById(new ObjectID(id)); console.log(result); }
refer: this answer.