mongoose (mongodb) Alias _id field

前端 未结 2 418
渐次进展
渐次进展 2020-12-18 19:29

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

2条回答
  •  鱼传尺愫
    2020-12-18 20:01

    You would use a virtual attribute for that. As in:

    yourSchema.virtual('ID').get(function() { return this._id; });
    

提交回复
热议问题