7

Mongoose connection best practices · GitHub

 1 year ago
source link: https://gist.github.com/pasupulaphani/9463004
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Mongoose connection best practices · GitHub

Instantly share code, notes, and snippets.

Mongoose connection best practices

thanks alot

Thank you much.

great job! thanks

Is it necessary to close connection after each request?

In mocha_test.js, is db ever defined?

after(function(done){
  db.connection.db.dropDatabase(function(){
    db.connection.close(function(){
      done();
    });
  });
});

nice, thanks!

What's the benefit of initializing express within the mongoose.connection.on section? And when you include the express initialization, all middleware and routes related code inside the mongoose.connection.on section, how do you avoid the express app from crashing because other files might be referencing the variable "app" which is used here to initialize express?

According to the Mongoose FAQ:

Q. Should I create/destroy a new connection for each database operation?
A. No. Open your connection when your application starts up and leave it open until the application shuts down.

I'm still working on sussing out all the info out there, it looks like there are two camps.

@jsonberry Which means the connection instance is shared for all requests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK