Is it possible with mongoose use a different name, in my case uppercase \'ID\', as an alias for the schema _id field? Would I need to add a virtual or is there another way o
The easiest way is to specify alias
in the schema:
let s = new Schema({
_id: { type: String, alias: "ID" }
});
This automatically creates both getter and setter, so it is possible to use ID
everywhere instead of _id
.
Mongoose documentation on aliases
You would use a virtual attribute for that. As in:
yourSchema.virtual('ID').get(function() { return this._id; });