目标:在引用的模型中返回用户信息。
问题:我相信我的模型名称(缺乏约定)会抛弃填充函数。我想返回我的用户名,但我没有得到它。
这是我的用户模型:
<div id="test">
Some information here.
</div>
function refreshFunc(){
document.getElementById("test").innerHTML = "DataFromPHP";
}
我的项目模型:
const UserSchema = new Schema({
profile: {
firstName: { type: String },
lastName: { type: String }
},
});
module.exports = mongoose.model('user', UserSchema, 'user');
在我的控制器中,我的功能如下:
const ItemSchema = new Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'user',
},
const PlayLoop = mongoose.model('items', ItemSchema);
返回的是我的商品型号:
show(req, res, next) {
const id = req.params.id
Items.findById({_id: id})
.populate({
path:'User',
})
.exec(function(err, item) {
if (err) {console.log(err)}
console.log(item)
})
},
对于用户,我想返回完整的个人资料信息。 想法?
答案 0 :(得分:0)
问题是客户端代码未指向正确的数据库。