From 162de5153bfed9581530d5ea1c768216b111f455 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 28 May 2019 17:42:11 -0700 Subject: [PATCH] Added MongoDbChangeStream option. --- db.js | 6 +++--- meshcentral.js | 6 +++--- sample-config.json | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/db.js b/db.js index 0226a576..c487b806 100644 --- a/db.js +++ b/db.js @@ -230,8 +230,8 @@ module.exports.CreateDB = function (parent, func) { }); // Setup the changeStream on the MongoDB main collection if possible - try { - obj.fileChangeStream = obj.file.watch([{ $match: { 'fullDocument.type': { $in: [ 'node', 'mesh', 'user' ] } } }], { fullDocument: 'updateLookup' }); + if (parent.args.mongodbchangestream == true) { + obj.fileChangeStream = obj.file.watch([{ $match: { 'fullDocument.type': { $in: ['node', 'mesh', 'user'] } } }], { fullDocument: 'updateLookup' }); obj.fileChangeStream.on('change', function (change) { switch (change.fullDocument.type) { case 'node': { dbNodeChange(change); break; } // A node has changed @@ -240,7 +240,7 @@ module.exports.CreateDB = function (parent, func) { } }); obj.changeStream = true; - } catch (ex) { } + } // Setup MongoDB events collection and indexes obj.eventsfile = db.collection('events'); // Collection containing all events diff --git a/meshcentral.js b/meshcentral.js index 11d77e43..2699dcbb 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -869,12 +869,12 @@ function CreateMeshCentralServer(config, args) { obj.updateServerState('state', 'running'); // Setup auto-backup defaults - if (obj.config.settings.autobackup == null) { obj.config.settings.autobackup = { backupinvervalhours: 24, keeplastdaysbackup: 10 }; } + if (obj.config.settings.autobackup == null) { obj.config.settings.autobackup = { backupintervalhours: 24, keeplastdaysbackup: 10 }; } else if (obj.config.settings.autobackup === false) { delete obj.config.settings.autobackup; } // Setup auto-backup timer - if (obj.config.settings.autobackup && (typeof obj.config.settings.autobackup.backupinvervalhours == 'number')) { - setInterval(obj.db.performBackup, obj.config.settings.autobackup.backupinvervalhours * 60 * 60 * 1000); + if (obj.config.settings.autobackup && (typeof obj.config.settings.autobackup.backupintervalhours == 'number')) { + setInterval(obj.db.performBackup, obj.config.settings.autobackup.backupintervalhours * 60 * 60 * 1000); } }); }); diff --git a/sample-config.json b/sample-config.json index 4915e816..d2ed42a4 100644 --- a/sample-config.json +++ b/sample-config.json @@ -3,6 +3,7 @@ "settings": { "_Cert": "myserver.mydomain.com", "_MongoDb": "mongodb://127.0.0.1:27017/meshcentral", + "_MongoDbChangeStream": true, "_WANonly": true, "_LANonly": true, "_Minify": 1, @@ -41,7 +42,7 @@ ] }, "_AutoBackup": { - "backupInvervalHours": 24, + "backupIntervalHours": 24, "keepLastDaysBackup": 10, "zipPassword": "MyReallySecretPassword3", "_backupPath": "C:\\backups"