Error with _id after updating to the latest NodeJS driver

We previously used our own UUID as a Binary type which worked perfect.

After updating to the latest NodeJS driver we noticed that we now get the error that our _id parameter should be the type ObjectId.

Is there a way to still use our own Binary as before?

Hi @Jens_Pauwels, yes it’s still possible. The Node driver team chose to implement it this way because ObjectId accounts for the majority of use-cases, but you should be able to get around this by specifying _id in your collection type. For example:

interface BinaryIdDocument {
  _id: Binary;
  [keys: string]: any
const coll = client.db('test').collection<BinaryIdDocument>('test');
coll.insertOne({ _id: new Binary(), mongo: 'db' });

Please let me know if that helps or if you have further questions. Thanks for reaching out!


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.