현재 4 가지 모델이 있습니다. 사용자, 프로필, 관심사 및 토큰. 사용자와 프로필 사이에는 일대일 관계가 있습니다. 사용자와 토큰 사이에는 일대 다 (one to many) 관계가 있습니다. 프로필과 관심사 사이에는 일대 다 관계가 있으며 관리자가 나중에 추가 할 수있는 기능이 미리 정의됩니다.관계로 몽구스 스키마를 더 잘 구조화하는 방법
사용자
var UserSchema = new Schema({
email: {
type: String,
lowercase: true,
unique: true,
required: true
},
phone: [{countrycode: String}, {number: String}],
tokens: [{type: Schema.Types.ObjectId, ref: 'Token'}],
profile: {
type: Schema.Types.ObjectId, ref: 'Profile'
},
},
{
timestamps: {createdAt: 'created_at', updatedAt: 'updated_at'}
});
프로필
var ProfileSchema = new Schema({
username: {
type: String,
unique: true,
},
firstname: {
type: String
},
lastname: {
type: String
},
gender: {
type: String
},
dob: {
type: Date
},
country: {
type: String
},
city: {
type: String
},
avatar: {
type: String
},
about: {
type: String
},
interests: [{
type: Schema.Types.ObjectId,
ref: 'Interest'
}],
},
{
timestamps: {createdAt: 'created_at', updatedAt: 'updated_at'}
});
토큰
var TokenSchema = new Schema({
name: {
type: String,
},
value: {
type: String,
},
},
{
timestamps: {createdAt: 'created_at', updatedAt: 'updated_at'}
});
관심
var InterestSchema = new Schema({
name: {
type: String,
unique: true,
},
},
{
timestamps: {createdAt: 'created_at', updatedAt: 'updated_at'}
});
이 schemeas/관계를 제대로 설정 했습니까? 이제 사용자에게 역할을 부여하려면 새 역할 스키마를 만들까요?
감사합니다.
임처럼, 다른 스키마 필드의 유형으로 스키마를 사용, 그래서 난 사람들을 저장하는 데 필요한 경우가 구성되는 방법을 말해 것입니다 데이터? – KayTokyo