Skip to content

Set _id from another input field #14310

Answered by vkarpov15
AaronPorts asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, however you would have to add one yourself using something like the following:

schema.virtual('id').get(function() { return this._id; }).set(function(v){ this._id = v; return v; });

Mongoose briefly had a virtual like this between versions 7.4 and 8.0, but we had to remove it because the virtual caused too many hard-to-debug issues for existing codebases to enable it by default. But there's nothing stopping you from adding that to your codebase.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by AaronPorts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants