In my Device model, I have multiple devices on which CRUD operations are regularly performed with success.
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const DeviceSchema = new Schema({
inventoryNumber: String,
deviceDescription: String,
supplier: String,
price: String,
comment: String,
debits: [
{
type: Schema.Types.ObjectId,
ref: "Debit",
},
],
});
module.exports = mongoose.model("Device", DeviceSchema);
Additionally, there is a Debit model that should contain information related to the Device model.
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const DebitSchema = new Schema({
debitDate: String,
devices: [
{
type: Schema.Types.ObjectId,
ref: "Device",
},
],
employees: [
{
type: Schema.Types.ObjectId,
ref: "Employee",
},
],
});
module.exports = mongoose.model("Debit", DebitSchema);
When adding a new Debit (using new.ejs), I aim to include a dropdown list with Device model data in the form (e.g. device.deviceDescription).
Suppose there are 5 devices (Device) already present in the database and I wish to view them in the dropdown list during Debit creation.
Therefore, the query is about populating the dropdown list with Devices' data and establishing a connection between these two models for accessing Devices from Debits?
I attempted iteration but encountered difficulties. Any guidance would be greatly appreciated.