Added MongoDbChangeStream option.

This commit is contained in:
Ylian Saint-Hilaire 2019-05-28 17:42:11 -07:00
parent 8416b0a0aa
commit 162de5153b
3 changed files with 8 additions and 7 deletions

6
db.js
View File

@ -230,8 +230,8 @@ module.exports.CreateDB = function (parent, func) {
}); });
// Setup the changeStream on the MongoDB main collection if possible // Setup the changeStream on the MongoDB main collection if possible
try { if (parent.args.mongodbchangestream == true) {
obj.fileChangeStream = obj.file.watch([{ $match: { 'fullDocument.type': { $in: [ 'node', 'mesh', 'user' ] } } }], { fullDocument: 'updateLookup' }); obj.fileChangeStream = obj.file.watch([{ $match: { 'fullDocument.type': { $in: ['node', 'mesh', 'user'] } } }], { fullDocument: 'updateLookup' });
obj.fileChangeStream.on('change', function (change) { obj.fileChangeStream.on('change', function (change) {
switch (change.fullDocument.type) { switch (change.fullDocument.type) {
case 'node': { dbNodeChange(change); break; } // A node has changed case 'node': { dbNodeChange(change); break; } // A node has changed
@ -240,7 +240,7 @@ module.exports.CreateDB = function (parent, func) {
} }
}); });
obj.changeStream = true; obj.changeStream = true;
} catch (ex) { } }
// Setup MongoDB events collection and indexes // Setup MongoDB events collection and indexes
obj.eventsfile = db.collection('events'); // Collection containing all events obj.eventsfile = db.collection('events'); // Collection containing all events

View File

@ -869,12 +869,12 @@ function CreateMeshCentralServer(config, args) {
obj.updateServerState('state', 'running'); obj.updateServerState('state', 'running');
// Setup auto-backup defaults // 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; } else if (obj.config.settings.autobackup === false) { delete obj.config.settings.autobackup; }
// Setup auto-backup timer // Setup auto-backup timer
if (obj.config.settings.autobackup && (typeof obj.config.settings.autobackup.backupinvervalhours == 'number')) { if (obj.config.settings.autobackup && (typeof obj.config.settings.autobackup.backupintervalhours == 'number')) {
setInterval(obj.db.performBackup, obj.config.settings.autobackup.backupinvervalhours * 60 * 60 * 1000); setInterval(obj.db.performBackup, obj.config.settings.autobackup.backupintervalhours * 60 * 60 * 1000);
} }
}); });
}); });

View File

@ -3,6 +3,7 @@
"settings": { "settings": {
"_Cert": "myserver.mydomain.com", "_Cert": "myserver.mydomain.com",
"_MongoDb": "mongodb://127.0.0.1:27017/meshcentral", "_MongoDb": "mongodb://127.0.0.1:27017/meshcentral",
"_MongoDbChangeStream": true,
"_WANonly": true, "_WANonly": true,
"_LANonly": true, "_LANonly": true,
"_Minify": 1, "_Minify": 1,
@ -41,7 +42,7 @@
] ]
}, },
"_AutoBackup": { "_AutoBackup": {
"backupInvervalHours": 24, "backupIntervalHours": 24,
"keepLastDaysBackup": 10, "keepLastDaysBackup": 10,
"zipPassword": "MyReallySecretPassword3", "zipPassword": "MyReallySecretPassword3",
"_backupPath": "C:\\backups" "_backupPath": "C:\\backups"