mongo db模式关系式或集合中

时间:2019-01-26 08:53:20

标签: mongodb

目前,我正在做一个辅助项目,希望对理解Mongo有帮助。我来自MySQL世界,因此有些概念在几分钟之内对我来说有点奇怪。

我的副项目本质上是一个项目组织者,一个项目可以具有3个区域,用户可以在其中上传多个文件/图像,项目资产,进行中的工作和可交付成果。

那么我应该为资产,在制品和可交付成果创建集合,然后将它们链接到项目吗?使用类似

 type: Schema.Types.ObjectId,
ref: "projects"

或者它们应该成为项目模式的一部分,为每个文件指定一种类型,而不是使项目模式看起来像

    // Create schema
const ProfileSchema = new Schema({
  name: {
    type: String,
    required: true
  },
  owner: {
    type: Schema.Types.ObjectId,
    ref: "users"
  },
  slug: {
    type: String,
    required: true,
    max: 40
  },
  status: {
    type: String,
    required: true
  },
  brief: {
    type: String,
    default: "No brief given"
  },
  date_due: {
    type: Date
  },
  created_at: {
    type: Date,
    default: Date.now
  },
  files: [
       name: {
           type: String
       },
       filepath: {
           type: String
       },
       type: {
          type: String
       }
  ]
});

如果我要启动该工具,则该集合中可能有1000行。

在关系数据库中,通常存在1:n关系的方式是否被接受?

0 个答案:

没有答案