Skip to content
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

Mongoose cannot register a global plugin on runtime #7042

Closed
vorillaz opened this issue Sep 22, 2018 · 1 comment
Closed

Mongoose cannot register a global plugin on runtime #7042

vorillaz opened this issue Sep 22, 2018 · 1 comment

Comments

@vorillaz
Copy link

vorillaz commented Sep 22, 2018

Do you want to request a feature or report a bug?
I think it's a bug

What is the current behavior?
I am trying to register a global plugin within a closure with not

If the current behaviour is a bug, please provide the steps to reproduce.
I am trying to bootstrap mongoose with a simple Express.js app. My app sets up a few dependencies and I am trying to pass a global plugin for mongoose within a closure. The console.log does not work at all and the methods are missing from my schemas.

const mongoose = require('mongoose');

const config = {};
const {DB_CONNECT} = process.env;

const myPlugin = schema => {
  console.log('done'); // this line is not executed
  schema.methods.mymethod = () => {};
}

const connectAndAddPlugins = async () => {
  await mongoose.connect(
    DB_CONNECT,
    {...config}
  );
  mongoose.plugin(myPlugin)
};

connectAndAddPlugins();

What is the expected behavior?
mymethod shall be present to my internal models.

Please mention your node.js, mongoose and MongoDB version.
node.js: v9.3.0
mongoose: ^5.2.13
MongoDB: v4.0.2

@vorillaz
Copy link
Author

Apparently, since mongoose compiles the first model global plugins are not applied any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant