English 中文(简体)
关于如何模仿这一数据库的一些建议
原标题:Some advice on how to model this database

我正在建立一个有用户的网站。 用户可以搜索歌曲,(如果是签名的话)可以将其保存到演唱者或其歌曲图书馆。

我想让主人喜欢,因为歌舞厅上的所有歌曲都是图书馆的一部分,这样,当使用者选择观看他们的歌曲图书馆时,表演者的歌曲以及刚刚添加到图书馆的歌曲就能够展示。 我喜欢一首歌,能够储存在多个游乐场。

现在,我正在使用Mongodb, 做这样的事情:

var UserSchema = new Schema();

var Library = new Schema({
    songs: [SongsSchema],
    user: Schema.ObjectId
});

var Playlist = new Schema({
title: String,
description: String,
user: Schema.ObjectId   
});

var SongsSchema = new Schema({
position: Number,
name: String,
artist: String,
    artistGid: String,
album: String,
    albumGid: String
time: Number,
url: String,
    gid: String,
    location: String (either youtube, vimeo, soundcloud for now),
    playlist: [Schema.ObjectId] (array of object ids that point to playlists?)
});

这似乎最好吗? 我与大家的关系一样,似乎有很多重复之处,但我很难以能够奏效的方式使这一局面正常化。

问题回答

认为我是合理的。 虽然在这种设计中,你可以不支持所订购的游戏清单。 如果你想要支持这一特征,我就包括一个对游乐器的反对和在游乐阵中的地位。

welcome to Mongo!

这样做是好的,只是确保你有一幅歌曲索引。 论文

db.collection.ensureIndex({"songs.playlist": 1})

Might make sense to make libraries / playlists the same thing, just have the title of the library object be "Library"





相关问题
How to model a many-to-many relationship in App Engine?

I have a question regarding how to model a many-to-many relationship in App Engine: A Blogentry can have many tags, a tag can apply to many blog entries. I see a couple of scenarios: Use a Set of ...

How to emulate tagged union in a database?

What is the best way to emulate Tagged union in databases? I m talking about something like this: create table t1 { vehicle_id INTEGER NOT NULL REFERENCES car(id) OR motor(id) -- not valid ... } ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

How to best implement a 1:1 relationship in a RDBMS?

Yesterday while working on a project I came up on a peculiar 1:1 relationship which left me wondering - how to best implement this (clearly, we had done it wrong :D) The idea is that there are two ...

Automatic filling entity properties

I have some type an architect(?) question I develop an application, based on Spring and Hibernate (annotated configuration) For each table in my database I added 4 fields: createdBy and modifiedBy(...

热门标签