node.js - One to Many relationship in Express Models using mongoDB -
this doctors.js
model:
var mongoose = require('mongoose'), schema = mongoose.schema; var patient = require('./patient.js'); var doctorschema = mongoose.schema({ firstname: string, lastname: string, qualifications: string, photo: buffer, _patients: [{ type: schema.types.objectid, ref: 'patient' }] }); var doctor = mongoose.model('doctor', doctorschema); module.exports = doctor;
this patients.js
model:
var mongoose = require('mongoose'); var doctor = require('./doctor.js'); var patientschema = mongoose.schema({ firstname: string, lastname: string, dob: string, gender: string, primarydiagnosis: string, duration: string, _doctorincharge: {type: number, ref: 'doctor'}, hospitalnumber: string, photo: buffer }); var patient = mongoose.model('patient', patientschema); module.exports = patient;
is way make 1 many relationship work?
Comments
Post a Comment