Fix for MongoDB change stream exception (#4429)

This commit is contained in:
Ylian Saint-Hilaire 2022-08-22 10:42:50 -07:00
parent af1e5f52ca
commit 0ce946bd90
1 changed files with 25 additions and 7 deletions

30
db.js
View File

@ -3236,8 +3236,14 @@ module.exports.CreateDB = function (parent, func) {
// Update the mesh object in memory // Update the mesh object in memory
const mmesh = parent.webserver.meshes[mesh._id]; const mmesh = parent.webserver.meshes[mesh._id];
for (var i in mesh) { mmesh[i] = mesh[i]; } if (mmesh != null) {
for (var i in mmesh) { if (mesh[i] == null) { delete mmesh[i]; } } // Update an existing device group
for (var i in mesh) { mmesh[i] = mesh[i]; }
for (var i in mmesh) { if (mesh[i] == null) { delete mmesh[i]; } }
} else {
// Device group not present, create it.
parent.webserver.meshes[mesh._id] = mesh;
}
// Send the mesh update // Send the mesh update
if (mesh.deleted) { mesh.action = 'deletemesh'; } else { mesh.action = (added ? 'createmesh' : 'meshchange'); } if (mesh.deleted) { mesh.action = 'deletemesh'; } else { mesh.action = (added ? 'createmesh' : 'meshchange'); }
@ -3256,8 +3262,14 @@ module.exports.CreateDB = function (parent, func) {
// Update the user object in memory // Update the user object in memory
const muser = parent.webserver.users[user._id]; const muser = parent.webserver.users[user._id];
for (var i in user) { muser[i] = user[i]; } if (muser != null) {
for (var i in muser) { if (user[i] == null) { delete muser[i]; } } // Update an existing user
for (var i in user) { muser[i] = user[i]; }
for (var i in muser) { if (user[i] == null) { delete muser[i]; } }
} else {
// User not present, create it.
parent.webserver.users[user._id] = user;
}
// Send the user update // Send the user update
var targets = ['*', 'server-users', user._id]; var targets = ['*', 'server-users', user._id];
@ -3273,8 +3285,14 @@ module.exports.CreateDB = function (parent, func) {
// Update the user group object in memory // Update the user group object in memory
const uusergroup = parent.webserver.userGroups[usergroup._id]; const uusergroup = parent.webserver.userGroups[usergroup._id];
for (var i in usergroup) { uusergroup[i] = usergroup[i]; } if (uusergroup != null) {
for (var i in uusergroup) { if (usergroup[i] == null) { delete uusergroup[i]; } } // Update an existing user group
for (var i in usergroup) { uusergroup[i] = usergroup[i]; }
for (var i in uusergroup) { if (usergroup[i] == null) { delete uusergroup[i]; } }
} else {
// Usergroup not present, create it.
parent.webserver.userGroups[usergroup._id] = usergroup;
}
// Send the user group update // Send the user group update
usergroup.action = (added ? 'createusergroup' : 'usergroupchange'); usergroup.action = (added ? 'createusergroup' : 'usergroupchange');