【发布时间】:2019-09-03 00:27:42
【问题描述】:
所以我正在创建一个音乐播放器,并想从歌曲架构(已经创建)创建一个专辑架构。
在专辑架构中,有一个专辑标题和一组歌曲。现在,如果歌曲名称相同,我想将它们添加到专辑中。
我如何做到这一点?
我已经按专辑标题对歌曲集进行了排序,但不知道如何将歌曲添加到歌曲数组中,如果它们具有相同的专辑标题。
//This is the song Schema.
var Song = mongoose.model('Songs', {
album: String,
title: String,
artist: String,
genre: String,
year: Number,
src: String
});
//This is the Album Schema.
const AlbumSchema = new Schema({
album: String,
songs: [{
title: String,
artist: String,
genre: String,
year: Number,
src: String
}]
});
还有没有办法在专辑模式中嵌套歌曲模式?
【问题讨论】:
标签: javascript node.js mongoose mongoose-schema mongoose-populate