so i am trying to select a specific array from my department-> dStock collection.
i want to select it like i would any other data fields in my initial collection and edit or delete it or simply check for duplicates before adding info.
What I have tried:
let departmentStock = await Department.findOne({
departmentName,
departmentProperty,
dStock: { itemCode, itemName },
i am not sure about the last line above, here i want to filter by department stock(dStock) then edit this information and reinsert it or simply update it });
as shown below dStock is an array of items withing the department Module.
const DepartmentSchema = new mongoose.Schema(
{
departmentName: { type: String, required: true, trim: true, minlength: 3 },
dStock: [
{
itemCode: { type: String, required: true, trim: true, minlength: 3 },
itemName: { type: String, required: true, trim: true, minlength: 3 },
itemQty: { type: Number, trim: true },
},
],
dOpenTime: { type: Date, trim: true, minlength: 4 },