Reputation: 1
I have the Cast to error in JSON response when Adding the Product Details in the & when adding category showing Error.
const mongoose = require("mongoose"); const { ObjectId } = mongoose.Schema;
{
category: { type: ObjectId, ref: "Category", },
};
Except category Every detail is adding in the mongodb table
Upvotes: 0
Views: 1012
Reputation: 90
You should try mongoose.SchemaTypes.ObjectId
@Prop({ type: mongoose.SchemaTypes.ObjectId, ref: 'ExercisePlan' })
category: string;
And if you are trying to aggregate with _id so you should try
$match: {
category: new Types.ObjectId(inputId),
},
Upvotes: 0