I have been trying to use the MongoDB findOne method but I don't know how use it. The problem is that I have a shema:
const CartSchema = mongoose.Schema({
user_id: { type: String },
products: [{
prod_id: { type: String },
qty: { type: Number }
}]
});
And this is my query:
ShoppingCart.findOne(
{ $and: [
{ user_id: Item.idUser },
{ products: [{ prod_id: Item.idProd }] } // my problem is here
] },
callback
);
I need to find this data within the {products} object but and I don't know how to refer to this position