-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconecction.js
More file actions
44 lines (36 loc) · 1.08 KB
/
conecction.js
File metadata and controls
44 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
// mongoose.connect('mongodb://192.168.99.100:32768/prueba');
// Se conecto a un container de docker
/* const connection = mongoose.createConnection('mongodb://192.168.99.100:27017/auth', (err, res) => {
if (err) return console.log('Error al conectar con la base de datos: ' + err)
console.log('Conexión a la base de datos establecidad....');
});
*/
// require('dotenv').config();
const prod_uri = process.env.MONGO_URI || 'mongodb://192.168.99.100:27017/auth';
const test_uri = process.env.MONGO_URI || 'mongodb://192.168.99.100:27017/test';
class Connect {
constructor(mode) {
this.mode = mode;
}
connect() {
const uri = this.uri();
mongoose.connect(uri);
return mongoose.connection; // Devuelvo la connection
}
uri() {
return this.mode ? test_uri : prod_uri;
}
connection() {
return mongoose.connection;
}
createConnection() {
const uri = this.uri();
return mongoose.createConnection(uri);
}
disconnect() {
mongoose.disconnect();
}
}
module.exports = Connect;