mongoose (mongodb) Alias _id field
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; });