I am facing a challenge with my app where I need to create an order with multiple attributes, one of which is an array of ordered products. Each object in the orderedProduct array must include the productId and the amount.
However, I do not want to create a new collection named OrderedProduct. The current solution is creating both an empty orderedproduct and orders, resulting in an issue:
"Cast to ObjectId failed for value \"{\n productId: { _id: '0a8b51d0-5bb1-4ab6-83d0-5b0c15f44e2b' },\n amount: 3\n}\" (type Object) at path \"_id\" for model \"OrderedProduct\""
Schemas
@Schema()
export class Order {
@Prop()
_id: string
@Prop({ type: Date, default: Date.now })
confirmedDate: Date
@Prop({ type: Types.ObjectId, ref: OrderStatus.name })
orderStatus: OrderStatus
@Prop()
userName: string
@Prop()
email: string
@Prop()
phoneNumber: string
@Prop({ type: Types.ObjectId, ref: OrderedProduct.name })
orderedProductArray: [OrderedProduct]
}
@Schema()
export class OrderedProduct {
@Prop(() => Int)
amount: string
@Prop({ type: Types.ObjectId, ref: Cloth.name })
product: Cloth
}
I have been unable to resolve this issue on my own. Any assistance would be greatly appreciated!