-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Schema#alias()
function that defines a new alias
#12368
Comments
I'd like to see an example of where this could be used just out of curiosity. |
One approach is schema aliases. For example, here's how we convert GitHub API's We don't have good support for multiple aliases, but you can always write your own virtuals that support multiple aliases. |
Schema#alias()
function that defines a new alias
…tiple aliases for a given path Fix #12368
feat(schema): add `alias()` method that makes it easier to define multiple aliases for a given path
Prerequisites
🚀 Feature Proposal
When creating documents from api data, users will sometimes have their schemas be identical to the keys coming in. Therefore, I propose we create a function that does the mapping and returns the resultant object.
Motivation
It is a bit tedious to have to manually map the result of the api call to your documents when the keys are identical. We could possibly take this one step further and implement an option that converts the keys of the apiResult to match the ones defined in mongoose. So if an api is in snake case but your models are in camel case, the function would convert the keys to camel, then map.
Example
The text was updated successfully, but these errors were encountered: