【问题标题】:Populate a array of objects in mongo with node使用节点填充 mongodb 中的对象数组
【发布时间】:2020-01-19 21:02:19
【问题描述】:

我有这个模型

var clienteSchema = new mongoose.Schema({
    nome:            String,
    profissao:       String,
    estado_civil:    String,
    data_nascimento: String,
    cpf:             String,
    cidade:          String,
    endereco:        String,
    data_cadastro:   {
        type:    Date,
        default: Date.now
        },
    telefone:        String,
    estadias:        [{
        type: mongoose.Schema.Types.ObjectId,
        ref: "Estadia"
    }]
});

我正在尝试填充但无济于事。

Cliente.findById({ _id: req.params.id }).populate("estadias.Estadia").exec((err,cliente)=>{

我该怎么做?

【问题讨论】:

  • 我想你只是想要populate("estadias")

标签: javascript arrays node.js mongodb object


【解决方案1】:

您只需要使用函数 .populate ("estadias") 但首先确保您的数据库中有数据,在这种情况下,我正在尝试,但创建文档时的另一个错误使其为空

【讨论】:

    猜你喜欢
    • 2021-07-12
    • 2014-09-22
    • 2018-03-28
    • 1970-01-01
    • 2021-05-23
    • 2021-07-18
    • 2022-06-13
    • 2021-07-09
    • 1970-01-01
    相关资源
    最近更新 更多