-
Type: Task
-
Resolution: Done
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
NODE-3803 Description
What problem are you facing?
After updating to 4.2.1 from 4.1.4 we are having issues managing types where the _id is a string instead of ObjectId.
If `_id` is not required (i.e. allow undefined) InferIdType fails and infers the id to be ObjectId.
If we make `_id` required, InferIdType infers the type correctly, but then insertOne and similar functions require the `_id` to be present, even if we defined the proper pkFactory on the client
What driver and relevant dependency versions are you using?
We are using nodes driver version 4.2.1
Steps to reproduce?
import { randomUUID } from 'crypto' import { MongoClient, InferIdType } from 'mongodb' interface TestDocument1 { _id: string name: string } interface TestDocument2 { _id?: string name: string } type id1 = InferIdType<TestDocument1> // string type id2 = InferIdType<TestDocument2> // object id const client = await MongoClient.connect(url, { pkFactory: { createPk: randomUUID } }) client.db().collection<TestDocument1>('test_collection').insertOne({ name: 'test1'}) // compilation error client.db().collection<TestDocument2>('test_collection').insertOne({ name: 'test2'}) // compilation error
- is depended on by
-
NODE-3803 Typescript errors on _id after update to 4.2.1
- Closed