[英]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.