0
Hello, friends. Good evening! I’m having a problem developing an api, I need to query some attributes within an array of a Schema in Mongodb to add them to an email for an order.
Could someone help me? Below is the model of Schema:
I need to take the values of the items array, but only need price, Quantity and title.
const schema = new Schema({
customer: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Customer'
},
email: {
type: mongoose.Schema.Types.ObjectId,
required: false,
ref: 'Customer'
},
name: {
type: mongoose.Schema.Types.ObjectId,
required: false,
ref: 'Customer'
},
number: {
type: String,
required: false
},
createDate: {
type: Date,
required: true,
default: Date.now
},
status: {
type: String,
required: true,
enum: ['created', 'done'],
default: 'created'
},
items: [{
quantity: {
type: Number,
required: true
},
price: {
type: Number,
required: true
},
product: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Product'
},
title: {
type: mongoose.Schema.Types.String,
ref: 'Product'
}
}],
});
You’ve already taken a look at this recourse for Query in arrays?
– Tuxpilgrim
What is the question more specifically? What have you tried?
– Costamilam