Hello, friends. Good night! I'm having a problem in developing an api, I need to query some attributes within an array of a Schema in MongoDB to add them to an email in a request.
Can anyone help me? follows the Schema model below:
I need to get the values from the array 'items', however I 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'
}
}],
});