Node.js 如何填充mongoose中另一个数组中的对象数组中的每个元素?
我的数据库架构如下所示:-Node.js 如何填充mongoose中另一个数组中的对象数组中的每个元素?,node.js,mongodb,mongoose,nosql,Node.js,Mongodb,Mongoose,Nosql,我的数据库架构如下所示:- const CategorySchema = new Schema({ title: { type: String, required: true, unique: true, }, albums: [ { type: Schema.Types.ObjectId, ref: "albums" }, ], }); const AlbumSchema = new
const CategorySchema = new Schema({
title: {
type: String,
required: true,
unique: true,
},
albums: [
{
type: Schema.Types.ObjectId,
ref: "albums"
},
],
});
const AlbumSchema = new Schema({
albumName: {
type: String,
required: true,
unique: true,
},
by: {
type: String,
required: true,
},
albumImageUri: {
type: String,
required: true,
},
artistHeadline: {
type: String,
required: true,
},
songs: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "songs",
},
],
});
const SongSchema = new Schema({
songName: {
type: String,
required: true,
},
songImageUri: {
type: String,
required: true,
},
songAudioUri: {
type: String,
required: true,
},
});
所以有一个歌曲类别,里面有专辑,里面有歌曲。我想检索所有类别并填充相册数组中的每个元素和每个相册中歌曲数组中的每个歌曲