Answer the question
In order to leave comments, you need to log in
Communication with sub-schema via populate()
Hello.
Such a question on MongoDB and Mongoose ORM
There are two models in Mongoose. In one, there is a sub-circuit.
var mongoose = require('mongoose'),
Clinic = require('./clinic'),
Schema = mongoose.Schema;
var ClinicSchema = mongoose.Schema({
name: {
type: String,
trim: true,
required: true
},
procedures: [new Schema({
name: {
type: String,
trim: true,
required: true
},
alias: {
type: String,
trim: true,
required: true
},
time: {
type: Number
},
customTime: {
type: Number
}
}, {
ref: 'Clinic'
})]
});
module.exports = mongoose.model('Clinic', ClinicSchema);
var mongoose = require('mongoose'),
Patient = require('./patient'),
User = require('./user'),
Clinic = require('./clinic'),
Schema = mongoose.Schema;
var RecordSchema = Schema({
doctor: {
type: Schema.Types.ObjectId,
ref: 'User'
},
clinic: {
type: Schema.Types.ObjectId
},
date: {
type: Date,
default: new Date()
},
patient: {
type: Schema.Types.ObjectId,
ref: 'Patient'
},
procedures: {
type: Schema.Types.ObjectId
}
});
module.exports = mongoose.model('Record', RecordSchema);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question