-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Support mongoose.SchemaType.get() : custom getters across all instances of a schematype #6912
Comments
@vkarpov15 What if I want to get the original object in some cases? |
@Lanfei can you provide an example case? You can do something like |
@vkarpov15 Actually I don't have any example case now, just wanted to know the solution if I met this situation in the future :) Maybe we can also have something like |
Love it, great idea 👍 |
The syntax will be |
Hi This does not seem to work in v5.10.3: mongoose.Schema.ObjectId.get(v => v.toString()); And neither does this: mongoose.ObjectId.get(v => v.toString()); Full code: import mongoose from 'mongoose';
export const installDatabaseConnection = async (): Promise<void> => {
try {
await mongoose.connect('mongodb://db:27017', {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true,
});
mongoose.Schema.ObjectId.get((v) => v.toString());
} catch (err) {
console.log(err);
}
}; Kind regards Glenny |
@GlennyDC can you please define what you mean by "does not seem to work"? What is the behavior you're seeing and what is the behavior you expect? |
@vkarpov15 I am referring to this functionality: https://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-get Also described / mentioned in:
Expected behaviour: ownerId: {
type: mongoose.Schema.Types.ObjectId,
get: (v) => v.toString(),
required: true,
}, Actual behaviour: |
Re discussion on #6849
Example:
The text was updated successfully, but these errors were encountered: