Справочный документ Mongodb, передовой опыт и производительность, тип [] и внешний объект - PullRequest
0 голосов
/ 29 мая 2020

У меня в приложении следующая структура, и я ищу лучшую производительность, у меня две сущности.

Entity Device Entity AnalogInput (8 постоянных строк или 16) один лучший?

const Device = mongoose.model('device', new Schema({ name: String, ainputs: [] }));
const device = new Device();
device.ainputs = [Array of 8 or 16 ainputs here];
device.save();

или

const Device = mongoose.model('device', new Schema({ name: String }));
const Ainput = mongoose.model('ainput', new Schema({ ... 10 properties });

async function createAinputs(deviceId) {
  await Ainput.insertMany([Array of 8 or 16 ainputs here])
}

// Attaching ainputs
const device = await Device.findOne(deviceId);
device.ainputs = await Ainput.find({ deviceId });

Какой из них лучший?

1.- Создать массив входов как свойство устройства? (без объекта)

2.- Создайте отдельный объект и присоединитесь к модели, когда это потребуется.

...