db_manager.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. var dbURL = 'mongodb://' + server + ":" + port + '/' + dbName;
  10. return mg.createConnection(dbURL);
  11. /*/
  12. if (port) {
  13. mg.connect('mongodb://' + server + ":" + port + '/' + dbName);
  14. } else {
  15. mg.connect('mongodb://' + server + '/' + dbName);
  16. }
  17. return mg;
  18. //*/
  19. },
  20. getQAConnection: function(dbName) {
  21. //*/
  22. return mg.createConnection("mongodb://192.168.1.184:60666/" + dbName);
  23. /*/
  24. mg.connect('mongodb://192.168.1.184:60666/' + dbName);
  25. return mg;
  26. //*/
  27. },
  28. getLocalConnection: function(dbName) {
  29. //*/
  30. return mg.createConnection("mongodb://localhost/" + dbName);
  31. /*/
  32. mg.connect('mongodb://localhost:27017/' + dbName);
  33. return mg;
  34. //*/
  35. },
  36. getCfgConnection: function(dbName) {
  37. var config = require("../config.js");
  38. //*/
  39. var port = config.current.port;
  40. var dbURL = 'mongodb://' + config.current.server + ":" + config.current.port + '/' + dbName;
  41. return mg.createConnection(dbURL);
  42. /*/
  43. mg.connect('mongodb://' + config.current.server + ":" + config.current.port + '/' + dbName);
  44. return mg;
  45. //*/
  46. }
  47. };