【问题标题】:Mongoose populate how to get populate document in same object instead of sub document猫鼬填充如何在同一对象而不是子文档中填充文档
【发布时间】:2020-04-30 10:36:12
【问题描述】:

我正在使用 mongoose populate 来获取另一个文档。我正在获取数据,但是作为子文档而不是子文档,我如何才能获得同一个对象。

{
"key":"value"
"userid":{
_id:"userid"
}
}

但我需要像下面这样

{ “核心价值” “用户标识”:“用户标识” }

【问题讨论】:

    标签: node.js mongoose mongoose-populate


    【解决方案1】:

    您可以更改方案的属性。

    它:

     "userid":{
       type: Schema.Types.ObjectId,
       ref: "User"
     }
    

    开始:

    "userid":{
     id:{
     type: Schema.Types.ObjectId,
     ref: "User"
     }
    }
    

    【讨论】:

    • 实际上是我作为子文档获得的参考文档,而不是我想要获得的相同级别的文档响应
    猜你喜欢
    • 2021-10-07
    • 2021-02-11
    • 2013-10-05
    • 2017-05-07
    • 2016-08-17
    • 2015-07-28
    • 2021-04-26
    • 2016-05-16
    • 1970-01-01
    相关资源
    最近更新 更多