施放到objectId失败了value \&quort \&quot (键入字符串)在路径上\&quort'cattory \&quot'因为\&quot'bsontypeerror \

发布于 2025-02-10 15:10:56 字数 195 浏览 2 评论 0原文

在&添加类别显示错误时。

const mongoose = require(“ mongoose”); const {objectid} = mongoose.schema;

{

类别: { 类型:objectid, 参考:“类别”, },

};

除类别外,每个细节都在MongoDB表中添加

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半夏半凉 2025-02-17 15:10:56

您应该尝试mongoose.schematypes.objectid

@Prop({ type: mongoose.SchemaTypes.ObjectId, ref: 'ExercisePlan' })
    category: string;

,如果您试图与_id汇总,以便您应该尝试

$match: {
    category: new Types.ObjectId(inputId),
},

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),
},
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文