나는 Mongodb를 처음 사용하고 MySQL을 사용했습니다. 학습 단계에서 LinkedIn과 같은 사용자 프로필을 만들려고합니다. mongodb 스키마에서 일대 다 관계를 만드는 올바른 방법을 선택하는 것은 혼란 스럽습니다.사용자 프로필에 대한 몽구스 스키마, 1 대 많은 속성을 가진
컨텍스트 : 사용자는 여러 교육 자격과 경험을 가질 수 있습니다. 내가 두 번째 테스트하지 않았습니다
var userSchema = new mongoose.Schema({
name: {
first: String,
middle: String,
last: String,
},
gender: { type: Number, max: 3, min: 0, default: GENDERS.Unspecified },
age: Number,
education: [{type: String, detail: {
major: String,
degree: String,
grade: String,
startdate: Date,
enddate: Date,
remarks: String
}}],
experience: [{type: String, detail: {
position: String,
company: String,
dateofjoin: String,
dateofretire: String,
location: String,
responsibilities: [{type:String}],
description: String,
}}],
email: String
});
:
예 1 :
var userSchema = new mongoose.Schema({
name: {
first: String,
middle: String,
last: String,
},
gender: { type: Number, max: 3, min: 0, default: GENDERS.Unspecified },
age: Number,
education: [{type: Schema.Types.ObjectId, ref:'Education'}],
experience: [{type: Schema.Types.ObjectId, ref:'Experience'}],
email: String
});
예 2 다음 두 가지 방법으로 내가 같이 스키마를 만들려고하는 것이이다 선택권.
데이터를 가져 오거나 추가하기 위해 쿼리를 작성하는 동안 어느 것이 더 쉽고 간편합니까? 그런 시나리오를위한 스키마를 작성하는 더 좋은 방법이 있습니까?