Added docker compose file
This commit is contained in:
@@ -4,7 +4,18 @@ const models = require('../models')
|
||||
const mongodb_hostname = process.env.MONGODB_HOST || '0.0.0.0';
|
||||
const mongodb_port = process.env.MONGODB_PORT || 27017;
|
||||
const mongodb_database = process.env.MONGODB_DATABASE || 'lsp';
|
||||
const mongodb_url = 'mongodb://' + mongodb_hostname + ':' + mongodb_port;
|
||||
const mongodb_user = process.env.MONGODB_USER;
|
||||
const mongodb_pass = process.env.MONGODB_PASSWORD;
|
||||
|
||||
// Build the MongoDB URI based on whether authentication is provided
|
||||
let mongodb_url;
|
||||
if (mongodb_user && mongodb_pass) {
|
||||
// Authenticated connection
|
||||
mongodb_url = `mongodb://${mongodb_user}:${mongodb_pass}@${mongodb_hostname}:${mongodb_port}`;
|
||||
} else {
|
||||
// No authentication
|
||||
mongodb_url = `mongodb://${mongodb_hostname}:${mongodb_port}`;
|
||||
}
|
||||
|
||||
const client = new MongoClient(mongodb_url, { useUnifiedTopology: true });
|
||||
|
||||
@@ -21,33 +32,25 @@ var days = function(date) {
|
||||
}
|
||||
|
||||
var init = async function () {
|
||||
await client.connect(function (err) {
|
||||
if (err) {
|
||||
console.log('MongoDB Client error');
|
||||
console.log(err);
|
||||
return { error: "Error connecting to DB: " + err }
|
||||
try {
|
||||
await client.connect();
|
||||
_db = client.db(mongodb_database);
|
||||
_devices = _db.collection('devices');
|
||||
_data = _db.collection('data');
|
||||
_ipx_data = _db.collection('ipx-data');
|
||||
_events = _db.collection('events');
|
||||
_alerts = _db.collection('alerts');
|
||||
|
||||
if (mongodb_user && mongodb_pass) {
|
||||
console.log('MongoDB Client connected with authentication');
|
||||
} else {
|
||||
_db = client.db(mongodb_database);
|
||||
_devices = _db.collection('devices');
|
||||
_data = _db.collection('data');
|
||||
_ipx_data = _db.collection('ipx-data');
|
||||
_events = _db.collection('events');
|
||||
_alerts = _db.collection('alerts');
|
||||
|
||||
console.log('MongoDB Client connected');
|
||||
////////////////////////////
|
||||
// FLUSH DB BY UNCOMMENTING
|
||||
// _devices.deleteMany(function(err, objects){});
|
||||
// _data.deleteMany(function(err, objects){});
|
||||
// _ipx_data.deleteMany(function(err, objects){});
|
||||
// _events.deleteMany(function(err, objects){});
|
||||
// _alerts.deleteMany(function(err, objects){});
|
||||
|
||||
return null;
|
||||
console.log('MongoDB Client connected without authentication');
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('MongoDB Client error:', err);
|
||||
return { error: "Error connecting to DB: " + err };
|
||||
}
|
||||
};
|
||||
|
||||
var addData = async function (relay, device, element) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user