I am faced with a situation where I have an interface that is extending a MongoDB document, along with some sample data that is also extending that interface. Below is an outline of the interface:
export default interface IModel extends Document {
_id: ObjectId;
name: string;
data: string;
}
The sample data conforms to this interface structure. The _id field looks like a string of numbers and letters. However, I encounter an error when assigning a value to the sample data in the _id fields because TypeScript interprets it as a string, whereas the type should be ObjectId. So, my question is, how can I convert the value of the id to be of type ObjectId?
This is what I have attempted so far:
export const ModelSampleData: IModel = {
"_id": toObjectId(240nfkfn38943),
"name": "model",
"data": "modelstuffetc"
}
I would greatly appreciate any guidance on this matter!