I am trying to change_id from mongoose schema to 'id' like is shown here MongoDB: output 'id' instead of '_id'
Duplicate the ID field.
Schema.virtual('id').get(function(){
return this._id.toHexString();
});
// Ensure virtual fields are serialised.
Schema.set('toJSON', {
virtuals: true
});
I am using typescript and Schema does not seem to have a 'virtual' method nor a 'set' method, and keyword 'this' is not bound in this context either. Who knows their typescript equivalents?