var mongoose = require('mongoose')
mongoose.connect('mongodb://127.0.0.1/DocTest');
var patientsSchema = mongoose.Schema({
//This is the value I wanna populate in the rdvs collection.
ssn: String
//But I can't see to have it working.
});
var patients = mongoose.model('patients', patientsSchema);
var Max = new patients({
ssn: "okokok"
});
Max.save(function (err) {
if (err) {
console.log(err);
}
else {
console.log('wink')
}
});
var rdvsSchema = mongoose.Schema({
Heure: {
type: Date
},
patient: {
type: mongoose.Schema.Types.ObjectId, ref: 'patients'
}
});
var rdvs = mongoose.model('rdvs', rdvsSchema);
var rdvs1 = new rdvs({
Heure: 14
}
);
rdvs1.save(function (err) {
if (err) {
console.log(err);
}
else {
console.log('wonk')
}
});
This is the request I'm trying to have working :
rdvs.findOne().populate('patient').exec(function(err, rdvs){
console.log (rdvs.patient.ssn)
});
I'm struggling here, the issue here is I wanna add ssn's value from patients to my rdvs collection.