var ObjSchema = new Schema ({
productId: {type: Schema.Types.ObjectId, ref: "M_Data_Product", default: null},
qty: {type: Number, default: 0},
price: {type: Float, default: 0},
});
This is my cart model
var ObjSchema = new Schema({
name: {type: String, default: null},
categoryId: {type: Schema.Types.ObjectId, ref: "M_Data_Category", default: null}
});
This is Product model.
I want to cart records by particular categoryId. How should I find?
Model.aggregate([
{
"$lookup": {
"from": "Product", //collection name of product
"localField": "productId",
"foreignField": "_id",
"as": "product"
}
},
{
$match:{"product.categoryId":"exampleId"}
}
])