有没有简便的方法可以从猫鼬的其他特定文档组中检索文档?

时间:2018-10-21 13:20:23

标签: node.js mongodb mongoose

我正在尝试从个人资料架构中的以下数组中检索帖子,但似乎找不到从我所遵循的个人资料中检索帖子的简便方法: `     让profileSchema = new mongoose.Schema({

profilePic:{
    data:Buffer,
    contentType:String
},
firstname:{
    type:String,
    required:true
},
lastname:{
    type:String,
},
Identity:{
    type:mongoose.Schema.Types.ObjectId,
    ref:`Users`
},
gender: {
    type: String
},
birth_date:{
    type: mongoose.Schema.Types.Date,
    required:true
},
username:{
    type: String,
    max:30
},
followers:[{
    type: mongoose.Schema.Types.ObjectId,
    ref: `Profile`
}],
following:[{
    type: mongoose.Schema.Types.ObjectId,
    ref: `Profile`
}],
myposts: [{
    type: mongoose.Schema.Types.ObjectId,
    ref: `Post`
}],
City:{
    city:String,
    country: String
}
});

and here is the block that i tried using    Profile.findById(req.user.profileID)       .populate({         路径:“跟随”,         型号:“个人资料”,         填充:{           路径:“ myposts”,           型号:“发布”         }       })       .then(教授=> {         res.json(prof.posts)       }) `

0 个答案:

没有答案