如何在猫鼬中繁殖? var headSchema=新模式({ typename:String, 标题名称:字符串, 状态:{type:Number,默认值:1} }); var Head=猫鼬模型(“heads”,headSchema); var mgmtSchema=新模式({ 头型:弦, 类型:{type:Schema.Types.ObjectId,ref:“Head”}, 日期:日期, 日期:日期, 标题:字符串, 金额:数字, 描述:字符串, 在{type:Date,默认值:Date.now}处创建了_, 更新位置:{type:Date,默认值:Date.now}, 状态:编号 }); var HeadMgmt=mongoose.model(“HeadMgmt”,mgmtSchema); 头管理查找({}) .populate({path:“type”,选择:“headname”}) .exec(函数(错误、结果){ 控制台日志(结果); });

如何在猫鼬中繁殖? var headSchema=新模式({ typename:String, 标题名称:字符串, 状态:{type:Number,默认值:1} }); var Head=猫鼬模型(“heads”,headSchema); var mgmtSchema=新模式({ 头型:弦, 类型:{type:Schema.Types.ObjectId,ref:“Head”}, 日期:日期, 日期:日期, 标题:字符串, 金额:数字, 描述:字符串, 在{type:Date,默认值:Date.now}处创建了_, 更新位置:{type:Date,默认值:Date.now}, 状态:编号 }); var HeadMgmt=mongoose.model(“HeadMgmt”,mgmtSchema); 头管理查找({}) .populate({path:“type”,选择:“headname”}) .exec(函数(错误、结果){ 控制台日志(结果); });,mongoose,Mongoose,我有两个模式,也是外键引用。第二个模式有一些价值。我需要在一个html表格中显示列表。如何从头部模式打印头部名称?在mgmtSchema中,您需要将类型字段中的ref值从head更改为heads,因为您使用了heads设置头部模型,如下所示: var Head=mongoose.model(“heads”,headSchema); 所以你的mgmtSchema必须是这样的: [ { "_id": "5e13483dd62cd92e3c3e8dcd", "

我有两个模式,也是外键引用。第二个模式有一些价值。我需要在一个html表格中显示列表。如何从头部模式打印头部名称?

mgmtSchema
中,您需要将类型字段中的ref值从
head
更改为
heads
,因为您使用了
heads
设置头部模型,如下所示:

var Head=mongoose.model(“heads”,headSchema);
所以你的mgmtSchema必须是这样的:

[
    {
        "_id": "5e13483dd62cd92e3c3e8dcd",
        "headtype": "headtype",
        "type": {
            "_id": "5e1347671b0bd339e0521139",
            "headname": "headname 1"
        },
        "title": "title",
        "amount": 123,
        "description": "description",
        "created_at": "2020-01-06T14:46:21.906Z",
        "updated_at": "2020-01-06T14:46:21.906Z",
        "__v": 0
    }
]
var mgmtSchema=新模式({
头型:弦,
类型:{type:Schema.Types.ObjectId,ref:“heads”},
日期:日期,
日期:日期,
标题:字符串,
金额:数字,
描述:字符串,
在{type:Date,默认值:Date.now}处创建了_,
更新位置:{type:Date,默认值:Date.now},
状态:编号
});
当前填充代码的结果如下所示:

[
    {
        "_id": "5e13483dd62cd92e3c3e8dcd",
        "headtype": "headtype",
        "type": {
            "_id": "5e1347671b0bd339e0521139",
            "headname": "headname 1"
        },
        "title": "title",
        "amount": 123,
        "description": "description",
        "created_at": "2020-01-06T14:46:21.906Z",
        "updated_at": "2020-01-06T14:46:21.906Z",
        "__v": 0
    }
]

mgmtSchema
中,您需要将type字段中的ref值从
Head
更改为
heads
,因为您使用了
heads
如下设置头部模型:

var Head=mongoose.model(“heads”,headSchema);
所以你的mgmtSchema必须是这样的:

[
    {
        "_id": "5e13483dd62cd92e3c3e8dcd",
        "headtype": "headtype",
        "type": {
            "_id": "5e1347671b0bd339e0521139",
            "headname": "headname 1"
        },
        "title": "title",
        "amount": 123,
        "description": "description",
        "created_at": "2020-01-06T14:46:21.906Z",
        "updated_at": "2020-01-06T14:46:21.906Z",
        "__v": 0
    }
]
var mgmtSchema=新模式({
头型:弦,
类型:{type:Schema.Types.ObjectId,ref:“heads”},
日期:日期,
日期:日期,
标题:字符串,
金额:数字,
描述:字符串,
在{type:Date,默认值:Date.now}处创建了_,
更新位置:{type:Date,默认值:Date.now},
状态:编号
});
当前填充代码的结果如下所示:

[
    {
        "_id": "5e13483dd62cd92e3c3e8dcd",
        "headtype": "headtype",
        "type": {
            "_id": "5e1347671b0bd339e0521139",
            "headname": "headname 1"
        },
        "title": "title",
        "amount": 123,
        "description": "description",
        "created_at": "2020-01-06T14:46:21.906Z",
        "updated_at": "2020-01-06T14:46:21.906Z",
        "__v": 0
    }
]

@athira appu如果你也能投票支持这个答案,我将不胜感激。@athira appu如果你也能投票支持这个答案,我将不胜感激。