[英]Populate a array of objects in mongo with node
I have this model我有这个模型
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"
}]
});
I am trying this to populate but to no avail.我正在尝试填充但无济于事。
Cliente.findById({ _id: req.params.id }).populate("estadias.Estadia").exec((err,cliente)=>{
How I can do this?我怎么能做到这一点?
您只需要使用函数 .populate ("estadias") 但首先确保您的数据库中有数据,在这种情况下,我正在尝试但在创建文档时出现另一个错误使其为空
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.