我试图用猫鼬设计数据模型,但是我对构造文档的最佳方法感到困惑。
Entity Relationship Diagram (ERD) image
公司与Job有一对多关系,而用户与Job有多对多关系。敬畏约伯更好吗?
是否有更好的文档结构方式?
这是我第一次使用mongoose和Node.js。任何帮助将不胜感激
User.js
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
// Define collection and schema for User
var User = new Schema({
companies: [{
jobs: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Job'
}]
}],
applied_jobs: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Job'
}],
resumes: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Resume'
}]
}, {
collection: 'users'
});
module.exports = mongoose.model('User', User);
Job.js
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
// Define collection and schema for Job
var Job = new Schema({
created_by: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
submitted_resumes: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Resume'
}]
}, {
collection: 'jobs'
});
module.exports = mongoose.model('Job', Job);
Resume.js
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
// Define collection and schema for Resume
var Resume = new Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}
}, {
collection: 'resumes'
});
module.exports = mongoose.model('Resume', Resume);