Here’s my Claim Schema:
var Claims = mongoose.Schema({
billed_insurances:
[
{type: mongoose.Schema.Types.ObjectId, ref: 'Insurances'},
]
});
module.exports = mongoose.model("Claims", Claims);
Here’s my Patient Schema
var Patients = mongoose.Schema({
name:
{
first_name: {type: String, required: true},
last_name: {type: String, required: true}
},
insurances:
[
carrier: {type: mongoose.Schema.Types.ObjectId, ref: 'Carriers', required: true},
member_id: {type: String, required: true},
]
});
module.exports = mongoose.model("Patients", Patients);
I’m trying to store and populate a reference from ‘insurances’ in Patient to billed_insurances in Claims. Storing it is no problem, but I haven’t been able to successfully populate the billed_insurances array.
Here’s my populate call:
Claim.findOne({_id : claimId}).populate({path: 'billed_insurances'})
When I run this, billed_insurances comes back as an empty array. I’d like to keep insurances embedded within the Patient and not extrapolated to it’s own collection since it’s always accessed when other Patient info is accessed. I’ve tried making insurances it’s own subdocument, among other things, however still no luck. How should I accomplish this?