Hello,
I am trying to change string value to object Id. I tried several ways, but couldn’t get what I want.
const { ObjectId } = require(‘mongodb’);
const stringValue = ‘999’; // Your string value
try {
const objectId = ObjectId(stringValue);
console.log(objectId); // The converted ObjectId
} catch (error) {
console.error(‘Invalid string value:’, error);
}
Receiving an error as - MongoDB Node.js Driver is not supported.
I added mongodb dependency to my project.
Please do let me know solution to fix this issue.
Thanks in advance.