我的目标是在一个对象数组上运行mongoose方法。例如
const ItemSchema = mongoose.Schema({
name: String,
time: { type: Number, default: 24 }
});
ItemSchema.methods.minus2 = function() {
this.time -= 2;
this.save();
}
Api方法
app.get('/allItems', function(req, res) {
Item.find({}, function(err, items) {
// I want to run items.calculateTime(); but it is not possible.
// How would I run calculateTime function on the array of objects?
});
});