问题描述
我正在为编程中的填充函数而苦苦挣扎。
我想知道scrabContent中的board是什么,所以我把boardId放入scrabContent。
我的用户架构如下所示。
const userSchema = new mongoose.Schema({
email: {
type: String,unique: true,required: true,},password: {
type: String,name: {
type: String,required:true,follower : [String],following : [String],boardBookmark: [],scrabContent: [],songs: [],songsView: {
type: Number,default :0,profileImage: {
type: String,}
});
示例示例如下所示。
{
follower: [],following: [],scrabContent: [
{
commentsNum: 0,likes: [],scrabs: [Array],image: [Array],isDeleted: false,_id: 603cd56e73188103d458fcfb,title: 'zzsdad',content: 'sddassda',postUser: 'umpa',postUserId: 603751786587acfbf1052d34,boardId: 603cd4c873188103d458fcfa,time: '2021/03/01 20:52:13',__v: 0
}
],songs: [
{
id: '1469319400',type: 'songs',href: '/v1/catalog/kr/songs/1469319400',attributes: [Object],name: 'lovE AGAIN'
},{
id: '1265893529',href: '/v1/catalog/kr/songs/1265893529',name: 'Get You (feat. Kali Uchis)'
},{
id: '1265893532',href: '/v1/catalog/kr/songs/1265893532',name: 'Best Part (feat. H.E.R.)'
},{
id: '1356070221',href: '/v1/catalog/kr/songs/1356070221',name: 'Daniel'
},{
id: '1438474485',href: '/v1/catalog/kr/songs/1438474485',name: 'Falling'
}
],songsView: 0,_id: 603a84d9760444a652d2cc72,email: 'test',password: '$2b$10$w8b85O6KQwGIZ0D1x0TGle.qofoEC43OKI5cMSf7tfqld12fSUWlu',name: 'test',__v: 0
}
但是,当我使用 populate 函数查找板架构时,会出现空数组。
这是我的服务器代码。
await User.find({_id: req.user._id}).populate('scrabContent.boardId').exec((err,data) => {
console.log(data[0]);
});
=> scrabContent.boardId = []。 我不知道为什么会发生这种情况,因为当我调用 populate('scrabContent.postUserId') 时,用户架构很好。
怎么解决??为什么会这样??请帮帮我T_T
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)