How do I manage MongoDB connections in a Node.js web application?

前端 未结 11 2326
旧巷少年郎
旧巷少年郎 2020-11-22 02:42

I\'m using the node-mongodb-native driver with MongoDB to write a website.

I have some questions about how to manage connections:

  1. Is it enough using

11条回答
  •  无人及你
    2020-11-22 03:08

    If you have Express.js, you can use express-mongo-db for caching and sharing the MongoDB connection between requests without a pool (since the accepted answer says it is the right way to share the connection).

    If not - you can look at its source code and use it in another framework.

提交回复
热议问题