projeto-hit/TEST_SERVER1/whats/funcs/dbcloud.js

142 lines
2.3 KiB
JavaScript

const dotenv = require('dotenv');
dotenv.config({ path: `${process.cwd()}/.env` });
const path = require('path')
const MongoClient = require( 'mongodb' ).MongoClient;
const url = process.env.DB_URL;
var _db;
module.exports = {
connectToServer: function( callback ) {
MongoClient.connect( url, { useNewUrlParser: true }, function( err, client ) {
_db = client.db(process.env.DB_NAME);
return callback( err );
} );
},
getDb: function() {
return _db;
}
};
// // PRODUCTION CONNECTION
// const MongoClient = require( 'mongodb' ).MongoClient;
// const url = "mongodb://admin:d1nf54012022prod*@172.31.187.8:27017";
// var _db;
// module.exports = {
// connectToServer: function( callback ) {
// MongoClient.connect( url, { useNewUrlParser: true }, function( err, client ) {
// _db = client.db('db_omnihit');
// return callback( err );
// } );
// },
// getDb: function() {
// return _db;
// }
// };
// LOCA CONNECTION
// const MongoClient = require( 'mongodb' ).MongoClient;
// const url = 'mongodb://localhost:27017';
// var _db;
// module.exports = {
// connectToServer: function( callback ) {
// MongoClient.connect( url, { useNewUrlParser: true }, function( err, client ) {
// _db = client.db('db_omnihit');
// return callback( err );
// } );
// },
// getDb: function() {
// return _db;
// }
// }
/*
const MongoClient = require( 'mongodb' ).MongoClient;
const url = "mongodb://admin:d1nf54012022*@172.31.187.2:27017";
var _db;
module.exports = {
connectToServer: function( callback ) {
MongoClient.connect( url, { useNewUrlParser: true }, function( err, client ) {
_db = client.db('db_omnihit_todoo');
return callback( err );
} );
},
getDb: function() {
return _db;
}
};
*/
// const MongoClient = require( 'mongodb' ).MongoClient;
// const url = "mongodb://admin:d1nf5401@192.168.15.13/admin?retryWrites=true&w=majority";
// var _db;
// module.exports = {
// connectToServer: function( callback ) {
// MongoClient.connect( url, { useNewUrlParser: true }, function( err, client ) {
// _db = client.db('db_omnihit');
// return callback( err );
// } );
// },
// getDb: function() {
// return _db;
// }
// };