I have the following schema for an e-commerce clothing shop:
{{{
// Define the schema for the data
const ProductSchema = new mongoose.Schema({
name: String,
description: String, //client description of their product
category: { type: String, enum: productCategories},//shirt, t shirt,
material: String, //jean, cotton, ect
colors:[
{
color: String, //dark wash/ medium wash
sizes:[{
size: String,
inseams:[{
image: String,
inseam: Number,
price: Number,
stock: Number,
}]
}]
}
],
});
}}}
And I want to return a cursor to all the items that fit a specific color and category, say “Jeans” and “Medium wash”, but also only pointing to documents that have stock greater than 0.
If possible, I would later like to edit that cursor to return the subdocument that matches the color, size, and specific inseam the costumer requests.
I’m struggling a lot to build a query, it seems I need to use some form of aggregation but I’m really at a loss here-- I just started using MongoDB