【发布时间】:2019-09-19 18:31:39
【问题描述】:
我正在创建一个应用程序来显示新音乐。在登陆页面上会有一个部分显示最近上传的音乐。当用户点击歌曲时,它会将他们带到一个显示模板,该模板将显示艺术家姓名、标题、视频、描述和艺术家社交媒体。
我还想要一个部分来显示该歌曲中包含的所有艺术家。当用户单击艺术家姓名时,它将呈现一个包含该艺术家所有歌曲的页面。所以我在创建模式时遇到了问题,因为一首歌可以有多个艺术家。
我的旧架构旨在从表单中获取输入并在与艺术家没有任何关系的情况下显示它。
通过我的新模式,我试图在艺术家和歌曲之间建立关系。
旧架构
const mongoose = require("mongoose");
artistSchema = new mongoose.Schema({
name: String,
title: String,
image: String,
content: String,
description: String,
category: String,
soundcloud: String,
scName: String,
instagram: String,
igName: String,
twitter: String,
twName: String
});
module.exports = mongoose.model("Artist", artistSchema);
新架构
const mongoose = require("mongoose");
artistSchema = new mongoose.Schema({
name: String,
social: schema.ObjectId,
music: schema.ObjectId
});
module.exports = mongoose.model("Artist", artistSchema);
const mongoose = require("mongoose");
socialSchema = new mongoose.Schema({
soundcloud: String,
scName: String,
instagram: String,
igName: String,
twitter: String,
twName: String
});
module.exports = mongoose.model("Social", socialSchema);
const mongoose = require("mongoose");
musicSchema = new mongoose.Schema({
title: String,
image: String,
content: String,
description: String,
category: String
});
module.exports = mongoose.model("Music", musicSchema);
环顾了一会后,我发现了一些与我正在尝试做的事情相关的文档。 https://gist.github.com/fwielstra/1025038
所以我的问题是我的架构是否设置正确,如果我继续关注 Github 文档,是否会遇到任何问题。
【问题讨论】:
标签: node.js mongodb express mongoose ejs