olá, eu tenho as seguintes Collections:
1:
var hourmeterDeviceSchema = mongoose.Schema({
name: {type: String, required: true},
description: {type: String, required: true},
group: {type: schema.Types.ObjectId, ref: 'DeviceGroup', required:true},
device: {type: schema.Types.ObjectId, ref: 'Device', required:true},
inputs: [{
number: {type: Number, required: true},
description: {type: String, required: true},
time: {type: Number, required: true}
}]
},
{ collection: 'hourmeterDevices' });
mongoose.model('HourmeterDevice', hourmeterDeviceSchema);
2:
var mongoose = require('mongoose');
var schema = mongoose.Schema;
var hourmeterAlarmSchema = mongoose.Schema({
name: {type: String, required: true},
description: {type: String, required: true},
device: {type: schema.Types.ObjectId, ref:'HourmeterDevice', required:true},
input: {type: schema.Types.ObjectId, ref: '', required:true},
},
{ collection: 'hourmeterAlarms' });
mongoose.model('HourmeterAlarm', hourmeterAlarmSchema);
Na primeira, eu consigo referenciar 'group' e 'device' porque são collections separadas, como faço para referenciar um 'input' do array 'inputs' na segunda collection ?