{"record":{"id":"e00fda1bb01ad4c3","repo":"litedb-org/LiteDB","slug":"bson-type-not-supported-e00fda","errorCode":null,"errorMessage":"BSON type not supported","messagePattern":"BSON type not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"LiteDB/Engine/FileReader/Legacy/BsonReader.cs","lineNumber":148,"sourceCode":"            }\n            else if (type == 0x12) // Int64\n            {\n                return reader.ReadInt64();\n            }\n            else if (type == 0x13) // Decimal\n            {\n                return reader.ReadDecimal();\n            }\n            else if (type == 0xFF) // MinKey\n            {\n                return BsonValue.MinValue;\n            }\n            else if (type == 0x7F) // MaxKey\n            {\n                return BsonValue.MaxValue;\n            }\n\n            throw new NotSupportedException(\"BSON type not supported\");\n        }\n    }\n}","sourceCodeStart":130,"sourceCodeEnd":151,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Engine/FileReader/Legacy/BsonReader.cs#L130-L151","documentation":"Thrown by the legacy BsonReader (used when importing/reading v4-era data files via FileReader) when it encounters a BSON type code byte it does not recognize or support. The reader handles Double(0x01), String(0x02), Document(0x03), Array(0x04), Binary(0x05), ObjectId(0x07), Boolean(0x08), DateTime(0x09), Null(0x0A), Int32(0x10), Int64(0x12), Decimal(0x13), MinKey(0xFF), MaxKey(0x7F). Any other byte triggers NotSupportedException.","triggerScenarios":"Reading a legacy BSON file that contains an unsupported type code (e.g. 0x06 Undefined, 0x0B Regex, 0x0C DBPointer, 0x0D JavaScript, 0x0E Symbol, 0x0F JavaScriptWScope, 0x11 Timestamp). Encountered during db upgrade/import from external BSON sources.","commonSituations":"Importing BSON exported from MongoDB or an older LiteDB that used deprecated BSON types; corrupt or truncated data; a custom BSON writer producing non-standard type tags.","solutions":["Pre-process the source BSON to convert unsupported types to supported equivalents (e.g. regex to string, undefined to null).","Use a different reader (the MongoDB C# driver or a custom BSON parser) that supports the wider type set, then insert documents into LiteDB.","If the file is corrupt, restore from backup or skip the offending document.","File a feature request / check the LiteDB version for expanded type support."],"exampleFix":"// Not directly fixable in caller code — the legacy BsonReader has a fixed type table.\n// Workaround: convert the source file first.\n// before: reader.ReadFile(\"legacy.bson\") throws on type 0x0B (Regex)\n// after: pre-convert unsupported types using a full BSON parser, then write standard BSON:\n//   foreach doc in sourceBson: replace Regex/Undefined/etc with String/Null, then feed to LiteDB Insert.","handlingStrategy":"try-catch","validationCode":"// No pre-check available from the caller; the type table is internal to BsonReader.\n// If importing BSON from MongoDB, pre-scan/convert unsupported types using the MongoDB driver before feeding to LiteDB.\npublic BsonDocument ConvertUnsupportedTypes(BsonDocument doc)\n{\n    foreach (var k in doc.Keys.ToList())\n    {\n        var v = doc[k];\n        // example: convert any non-LiteDB-supported representation to string/null\n        if (v == null) doc[k] = BsonValue.Null;\n    }\n    return doc;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    using var reader = new LegacyBsonReader(stream);\n    // read documents...\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"BSON type not supported\"))\n{\n    // Skip the offending document or convert the source file with a full BSON parser first.\n    logger.LogWarning(ex, \"Skipped a document with an unsupported BSON type during legacy import.\");\n}","preventionTips":["Pre-convert BSON from MongoDB/other sources to LiteDB-supported types before import.","Map deprecated types (Regex, Undefined, DBPointer, Symbol) to String/Null equivalents.","Test legacy file imports on a sample before full migration.","Keep a copy of the original file in case conversion drops data."],"tags":["bson","legacy-reader","file-import","litedb-engine"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}