Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. const mongoose = require('mongoose');
  2.  
  3. exports.initialize = function () {
  4. return new Promise(function (resolve, reject) {
  5. console.log("initialize mongoDB...");
  6.  
  7. const option = {
  8. useMongoClient: true,
  9. config: {
  10. autoIndex: true
  11. },
  12. reconnectTries: Number.MAX_VALUE,
  13. reconnectInterval: 1000,
  14. poolSize: 300,
  15. connectTimeoutMS: 10000, // Give up initial connection after 10 seconds
  16. socketTimeoutMS: 20000, // Close sockets after 45 seconds of inactivity
  17. };
  18.  
  19. mongoose.connect('mongodb://localhost:27017/shop', option, function (error) {
  20. if (error) {
  21. logger.info("please make sure mongodb is running", dbConfig.mongoURL);
  22. reject(new Error(error));
  23.  
  24. process.exit(1);
  25. return;
  26. }
  27.  
  28. logger.info("connected to mongoDB", dbConfig.mongoURL);
  29. resolve();
  30. });
  31. });
  32. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement