简体   繁体   English

对MongoDB中设计Shift模式的怀疑

[英]Doubts about design Shift schema in MongoDB

I am coding an API Rest for a small project about Shifts for the employees but I am stuck in how to design the models. 我正在为一个关于员工的班次的小项目编写API Rest,但是我仍然沉迷于如何设计模型。 I found a way to design it but I have doubts if it is the best way. 我找到了一种设计方法,但是我怀疑它是否是最佳方法。

My collections are: 我的收藏是:

  • Users: (Employees) 用户:(员工)
  • Positions: (Employee Position) 职位:(员工职位)
  • Shift: ( start - end time based on the employee position.) 班次:(开始-结束时间基于员工的职位。)
  • Record: (day of the shift, shift and employees) 记录:(轮班日,轮班和员工)
  • Rota: (information about rota) 花名册:(有关名册的信息)

Users can have more than one position. 用户可以拥有多个职位。

The shifts only have one position. 档位只有一个位置。

Records collect the shifting the array of employees and references about rota. 记录收集轮换的员工和关于rota的参考。

I will simplify my code: 我将简化我的代码:

const User = Schema({
   name: {type: String},
   position: [{type: Schema.Types.ObjectID, ref 'Positions'}]

});
const positions = Schema({
   name: {type: String}
});
const Shifts = Schema({
   start_time: {type: Date},
   end_time : {type: Date},
   position: {type: Schema.Type.ObjectID, ref 'Positions'}
});
const Records = Schema({
   start_date: {type: Date},
   end_date : {type: Date},
   shift: {type: Schema.Type.ObjectID, ref 'Shifts'},
   employees:[{type: Schema.Type.ObjectID, ref 'Users'}]

});

Do you think it is a good design to develop the schema or not? 您是否认为开发模式是一个好的设计?

Anything to improve? 有什么需要改进的吗? or something to change? 或有什么改变?

From my experience too many references in MongoDB slows the MongoDB. 根据我的经验,在MongoDB中有太多的引用使MongoDB变慢。 Your design is good when you are relational database.The concept of a Document database is that it eliminates lots of joins. 当您是关系数据库时,您的设计是好的。Document数据库的概念是,它消除了很多联接。 Try to place as much in a single document as you can. 尽量在单个文档中放置尽可能多的内容。 Because MongoDB documents have structure, and because you can efficiently query within that structure Also you don't have to normalise the data like you would in SQL. 因为MongoDB文档具有结构,并且因为您可以在该结构中高效地查询,所以您也不必像在SQL中那样规范化数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM