Issue with ObjectId

Hi

I am developing an API with NodeJS, but I am getting a issue with ObjectId( ). How could I fix it?

The Issue Message:

throw new BSONError('input must be a 24 character hex string, 12 byte Uint8Array, or an 
integer');
                   
BSONError: input must be a 24 character hex string, 12 byte Uint8Array, or an integer at new ObjectId

My Code:

const { ObjectId } = require('mongodb');

const collection = await database.collection('components');
const result = collection.updateOne({ _id : new ObjectId("165e9e740d1485865c897b63f") }, { $set : { component : "nodejs" } });

res.json(result).status(200);

Thank You

The error is

Your string in

has 25 hex characters. How did you get that value? I suspect the leading 1 is wrong.

1 Like

Thank You. My ID was wrong.