Monday, 6 May 2019

Property 'virtual' does not exist on type 'typeof Schema'

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?



from Property 'virtual' does not exist on type 'typeof Schema'

No comments:

Post a Comment