How can I calculate the length of a list in one of the parameters of a model, and add that length to another parameter of that same model so that it can be send back as part of the response by the api?
const mongoose = require('mongoose')
const Schema = mongoose.Schema;
const ArrayOfUser = require('../models/arrayofuser')
var usersSchema = new Schema({
items: {type: mongoose.Schema.Types.ObjectId, ref: 'ArrayOfUser'},
total: items.length
})
module.exports = mongoose.model('Users', usersSchema)
Solution
These are called virtual properties, functionality directly provided by mongoose:
Code
The way to achieve it in your case would be:
Followup to Comments:
Here is the fixed Node route method for the feedback below! Good luck :)