{"record":{"id":"e4cf45fa456aa23a","repo":"RocketChat/Rocket.Chat","slug":"invalid-settings-found-on-db-deleting-them","errorCode":null,"errorMessage":"Invalid settings found on DB. Deleting them.","messagePattern":"Invalid settings found on DB\\. Deleting them\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/meteor/server/lib/settingsRegenerator.ts","lineNumber":26,"sourceCode":"export async function settingsRegenerator() {\n\tconst invalidSettings = await Settings.find(\n\t\t{\n\t\t\t// Putting the $and explicit to ensure it's \"intentional\"\n\t\t\t$and: [\n\t\t\t\t{ value: { $exists: false } },\n\t\t\t\t{ type: { $exists: false } },\n\t\t\t\t{ public: { $exists: false } },\n\t\t\t\t{ packageValue: { $exists: false } },\n\t\t\t\t{ blocked: { $exists: false } },\n\t\t\t\t{ sorter: { $exists: false } },\n\t\t\t\t{ i18nLabel: { $exists: false } },\n\t\t\t],\n\t\t},\n\t\t{ projection: { _id: 1 } },\n\t).toArray();\n\n\tif (invalidSettings.length > 0) {\n\t\tlogger.warn({\n\t\t\tmsg: 'Invalid settings found on DB. Deleting them.',\n\t\t\tsettings: invalidSettings.map(({ _id }) => _id),\n\t\t});\n\t\tawait Settings.deleteMany({ _id: { $in: invalidSettings.map(({ _id }) => _id) } });\n\t\t// No need to notify listener\n\t} else {\n\t\tlogger.info('No invalid settings found on DB.');\n\t}\n}\n","sourceCodeStart":8,"sourceCodeEnd":36,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/settingsRegenerator.ts#L8-L36","documentation":"Logged by settingsRegenerator(), which runs as part of Rocket.Chat startup to validate the Settings MongoDB collection. It queries for documents that are missing ALL of the required structural fields (value, type, public, packageValue, blocked, sorter, i18nLabel) — i.e. completely malformed setting records — and deletes them with Settings.deleteMany. The warning lists the offending _ids so the operator can trace where they came from. After deletion the settings are regenerated from the code-defined registry on next startup.","triggerScenarios":"On every server startup, settingsRegenerator() finds at least one document in the Settings collection missing every required field ($exists: false for value, type, public, packageValue, blocked, sorter, i18nLabel). Typical producers: an interrupted insert/partial write, manual mongo shell inserts of stub documents, a bot or app writing placeholder setting docs, or a restored/damaged database.","commonSituations":"Upgrading very old or community-forked installations whose settings documents have drifted from the current schema; restoring a backup taken mid-write; running scripts that pre-created empty setting documents; Mongo replica failover leaving partial documents. Operators usually see this once after such an event and never again.","solutions":["Note the setting _ids printed in the warning and confirm none of them are entries you actually need — they were non-functional anyway (no value, no type).","Restart the server once more: the deleted stubs are regenerated from the code-defined defaults in the settings registry.","Find and stop whatever wrote the malformed documents (custom app, provisioning script, manual mongo insert) so they do not reappear.","If the warnings recur every startup, inspect the Settings collection (db.Settings.find({value: {$exists: false}, type: {$exists: false}, ...}) ) and take a backup before letting the regenerator run again."],"exampleFix":"// before: a script inserting a placeholder setting doc with no fields\ndb.Settings.insertOne({ _id: 'My_Custom_Setting' }); // triggers the warning on next startup\n\n// after: insert a fully-formed setting document\ndb.Settings.insertOne({\n  _id: 'My_Custom_Setting',\n  value: 'hello',\n  type: 'string',\n  public: false,\n  packageValue: 'hello',\n  blocked: false,\n  sorter: 0,\n  i18nLabel: 'My_Custom_Setting',\n});","handlingStrategy":"validation","validationCode":"// Run before/at startup to see which docs the regenerator will delete\nconst invalid = db.Settings.find({\n  $and: [\n    { value: { $exists: false } },\n    { type: { $exists: false } },\n    { public: { $exists: false } },\n    { packageValue: { $exists: false } },\n    { blocked: { $exists: false } },\n    { sorter: { $exists: false } },\n    { i18nLabel: { $exists: false } },\n  ],\n}, { _id: 1 }).toArray();\nprintjson(invalid); // empty array => warning will not fire","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never insert placeholder documents into the Settings collection; always include value, type, public, packageValue, blocked, sorter and i18nLabel.","Take a mongodump before major upgrades so settings deleted by the regenerator are recoverable.","Watch startup logs for the warning after restoring backups or running custom provisioning scripts, and fix the writer, not just the data."],"tags":["settings","mongodb","startup","data-cleanup","schema-validation"],"backgroundTag":"malformed-database-records","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}