【发布时间】:2014-09-20 03:55:28
【问题描述】:
当我在集合中填充引用时,被引用集合中的嵌入文档显示为 [Object] 而不是实际文档。
更多细节
我有一个歌曲架构
var songSchema=new Schema({
songName:String
});
专辑架构
var albumSchema=new Schema({
title:String,
favs:Number,
songs:[songSchema]
})
以及引用专辑的播放列表架构。
var playlistSchema=new Schema({
title:String,
items: { type: Schema.ObjectId, ref: 'Album' }
})
现在当我运行以下查询时
Playlist
.find()
.populate('items')
.exec(function (err, playlists) {
if (err) return handleError(err);
console.log("Result:"+playlists);
})
我得到以下结果
Result:{ _id: 53d6b605842416b83b5fe472,
title: 'Sad',
items:
{ _id: 53d6b605842416b83b5fe471,
title: 'Awaz',
favs: 500,
__v: 0,
songs: [ [Object], [Object] ] },
__v: 0 }
请注意歌曲数组如何具有 [Object] 数组而不是实际的嵌入对象。如何让实际文件显示出来?
【问题讨论】: