Im trying to create a FoodItem Schema In which i kept measureUnit as an object reference from another page's model.
This is MeasureTypesSchema where the measureUnit is present. MeasureTypes is a embedded array document inside MetricsSchema. I am exporting both MeasureTypesSchema's model (MeasureTypes) and MetricsSchema's model (Metrics).
var mongoose = require('mongoose');
Schema = mongoose.Schema;
var MeasureTypesSchema = new mongoose.Schema({
measureUnit:{type:String,required:true},
code:{type:String,required:true}
});
var MeasureTypes = mongoose.model('MeasureTypes', MeasureTypesSchema);
module.exports = MeasureTypes;
var MetricsSchema = new mongoose.Schema({
organisation:{type: Schema.Types.ObjectId, ref: 'Organisation'},
MeasureTypes:[MeasureTypesSchema]
});
var Metrics = mongoose.model('Metrics', MetricsSchema);
module.exports = Metrics;
This is FoodItemSchema where i kept measureUnit as an object reference from MeasureTypes model present in another page
var mongoose = require('mongoose');
Schema = mongoose.Schema;
var FoodItemSchema = new mongoose.Schema({
measureUnit:{type: Schema.Types.ObjectId, ref:'MeasureTypes',required:true},
});
var FoodItem = mongoose.model('FoodItem', FoodItemSchema);
module.exports = FoodItem;
I need to get the details of measureUnit when i populate, how to populate so that i get the details of measureUnit.