簡體   English   中英

使用節點填充 mongo 中的對象數組

[英]Populate a array of objects in mongo with node

我有這個模型

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") 但首先確保您的數據庫中有數據,在這種情況下,我正在嘗試但在創建文檔時出現另一個錯誤使其為空

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM