db_manager.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Created by Tony on 2017/3/9.
  3. */
  4. var mg = require('mongoose');
  5. //mg.connect('mongodb://localhost/Demo');
  6. module.exports = {
  7. getConnection : function(server, port, dbName) {
  8. //*/
  9. if (port) {
  10. return mg.createConnection(server + ":" + port,dbName);
  11. } else {
  12. return mg.createConnection(server,dbName);
  13. }
  14. /*/
  15. if (port) {
  16. mg.connect('mongodb://' + server + ":" + port + '/' + dbName);
  17. } else {
  18. mg.connect('mongodb://' + server + '/' + dbName);
  19. }
  20. return mg;
  21. //*/
  22. },
  23. getQAConnection: function(dbName) {
  24. //*/
  25. return mg.createConnection("192.168.1.184:60666",dbName);
  26. /*/
  27. mg.connect('mongodb://192.168.1.184:60666/' + dbName);
  28. return mg;
  29. //*/
  30. },
  31. getLocalConnection: function(dbName) {
  32. //*/
  33. return mg.createConnection("localhost:27017",dbName);
  34. /*/
  35. mg.connect('mongodb://localhost:27017/' + dbName);
  36. return mg;
  37. //*/
  38. },
  39. getCfgConnection: function(dbName) {
  40. var config = require("../config.js");
  41. //*/
  42. return mg.createConnection(config.current.server + ":" + config.current.port, dbName);
  43. /*/
  44. mg.connect('mongodb://' + config.current.server + ":" + config.current.port + '/' + dbName);
  45. return mg;
  46. //*/
  47. }
  48. };