Open chumager opened 3 years ago
First console log prints an id when it should print undefined
I took a closer look and you're right, this is a bug. We tried to refactor id
to be a plugin in #3936 for 6.0, made a note to undo that refactor, but didn't get to it. Lessons learned: make a separate issue instead of treating the issue as "done" but relying on a comment as a mental note to self.
We'll ship 6.0.7 with this fix on Monday :+1:
Hi, thanks for the solution, but IMHO I think there should be some kind of order to load plugins, instead of other solutions, at least three sections, something like before, middle (or nothing) and after.
Some examples:
For now I've to use the old school filename method to sort the way the plugins are loaded, but I've several layers, so at first my FW plugins are loaded, then the default apps plugins and finally the app plugins, so this kind of sort it's not perfect.
Regards.
The intention of plugins is that order is up to the end developer. The order you call .plugin()
is the order that the plugins are applied. Things just get a bit tricky with Mongoose's built-in plugins, because those are always defined first.
Another way is to modify mongoose.plugins
directly. plugins
is just an array of [function, PluginOptions]
, you can shuffle that around as you need to.
Hi, thanks for the answer, but I'm not able to "sort" manually the plugins, because I develop a framework, so the "plugin" stage is static and independent the framework user, maybe a could add a "position" to the plugin object definition.
Regards.
@chumager so something like mongoose.plugin(myPlugin, { position: 0 }) // <-- force this plugin to be first, no matter what
? Or are you looking for something more sophisticated, like support for a plugin dependency graph?
Hi @vkarpov15, I already thought about that kind of solution as I used in other parts of my code, but the meaning of using inside Mongoose is to help other developers.
My plugin objects looks like this:
{
plugin(schema, options) {//do something},
schemas: [ ],//optional, could be global
position: x// new, position
}
But yes... that's what I'm developing right now.
Best regards.
@chumager how would that work if two plugins have the same position
? Or would that throw an error?
Hi @vkarpov15 Just like any other sort system, FIFO...
Do you want to request a feature or report a bug? bug What is the current behavior? In one of my plugins I've set id
false
to avoid id in all my models, it worked on 5.13.x, but now it's not working in 6.0.x If the current behavior is a bug, please provide the steps to reproduce.What is the expected behavior? I'd like to be able to set id
false
globally, instead of using a plugin. For the moment I need a solution to avoid id alias in my models asSchema.set("id", false);
is not working in a plugin. What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version. Node 16.8.0 Mongoose 6.0.5 Mongodb atlas 4.4.8