I want to update or push a product in the products list,
for better performence im filtering by date/hours[hour]/categories[category]
EX:
{
date: "05/05/24",
"hours.hour": "09",
"hours.categories.category": "computers",
"hours.categories.products": {
$elemMatch: { product_source_id: 112233},
}
}
If path exists I want to update the product,
if some of the path like hours/category/etc.. doesnt exist I want to create it.
“upsert” does not help me cuz it just creates a whole new document but I want to modify the existing one
this is the Document Sceham
date: { type: String, required: true },
hours: [
{
hour: { type: String, enum: hoursEnum },
categories: [
{
category: { type: String, required: true },
products: [
{
product_source_id: { type: String, required: true },
last_published: { type: Date, required: true },
},
],
},
],
},
]
Im using mongoose