-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: TypeScript
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
- depends on
-
NODE-3804 Investigate NODE-3803 - Typescript errors on _id after update to 4.2.1
- Closed
- is duplicated by
-
NODE-3761 OptionalId should resolve optional custom types to the user type or ObjectId
- Closed
- is related to
-
NODE-3825 _id of Document should not have to be of type ObjectId
- Closed
- related to
-
NODE-3761 OptionalId should resolve optional custom types to the user type or ObjectId
- Closed