I have a schema like this:
const facturacionSchema = mongoose.Schema({
PrecioCantidad: Number,
Cantidad: Number,
Total: {
type: Number,
get: function() {
return this.PrecioCantidad * this.Cantidad
}
}
});
module.exports = mongoose.model('Facturacion', facturacionSchema);
And I want to find documents by "Total", like:
Facturacion.find({ Total: 1000 });
"Total" field is not in the database documents, is a calculated field. I don't mind if I have to do something like:
Facturacion.find({ PrecioCantidad * Cantidad: 1000 });
but I don't know how to find based on a calculation of two fields.
Thanks.