Upgrading MongoDB.Bson 2 to 3
Breaking2.30.0 → 3.13.0Breaking10Security23Deprecated1New96Changed42Fixed67Other21
SecurityWriting a raw BSON document or array now throws ArgumentException when its declared length is inconsistent with the buffer.CSHARP-6157 ↗
BreakingUpgrade verdict
10 breaking changes and 23 security fixes.
In plain terms
- If your class has an Id property with a [BsonElement] attribute that renames it to something other than _id, that property is no longer treated as the document identifier. Existing documents may not read correctly and new writes go to a different field.
- Atlas Search operators now respect your registered serializers. To keep the previous behavior, turn this off explicitly.
- The older LINQ2 query provider is gone, so code relying on it must move to the supported LINQ provider.
- Code that references IMongoQueryable directly will no longer compile.
Must act Top 5 of 34 that need code or config changes
MongoDB.Bson publishes an official migration guide for version 3. It covers more than the release notes do.
Upgrade guide ↗Target frameworks requirement changed in 3.0.0: .NETFramework4.7.2, .NETStandard2.0, .NETStandard2.1 → .NETFramework4.7.2, .NETStandard2.1, net6.0.
What you must change
Breaking10
Respects the BsonElement attribute in NamedIdMemberConvention, so members named Id, id or _id with a BsonElement naming something other than _id are no longer mapped as the document id.
BsonElementNamedIdMemberConventionBsonIdAtlas Search operators now use registered serializers by default; use SearchDefinition.UseConfiguredSerializers(false) for the old behavior.
SearchDefinition.UseConfiguredSerializers(false)Removes the LINQ2 provider.
Removes the IMongoQueryable interface.
IMongoQueryableRemoves the MongoDB.Driver.Legacy package.
MongoDB.Driver.LegacyRemoves the MongoDB.Driver.Core package and various non-user-facing APIs.
MongoDB.Driver.CoreMoves client side field level encryption to an optional MongoDB.Driver.Encryption package and drops MongoDB.Libmongocrypt.
MongoDB.Driver.EncryptionMongoDB.LibmongocryptRemoves MONGODB-CR authentication support.
MONGODB-CRChanges the default GUID serialization mode and removes GuidRepresentationMode.
GuidRepresentationModeMoves AWS authentication to an optional MongoDB.Driver.Authentication.AWS package.
MongoDB.Driver.Authentication.AWSSecurity23
Writing a raw BSON document or array now throws ArgumentException when its declared length is inconsistent with the buffer.
ArgumentExceptionStops interning BsonSymbol values and marks BsonSymbolTable obsolete to prevent memory-exhaustion denial of service.
BsonSymbolBsonSymbolTableBsonSymbol.CreateBsonBinaryData, the JSON reader and the binary writer now reject binary subtypes outside 0 to 255.
BsonBinaryDataBinDataHexData$typePushEach and AddToSetEach with a single value now always render $each, and PullAll with a single value always renders $pullAll.
PushEachAddToSetEachPullAll$each$pullAll$pullFixes cross-document data leak via malformed BSON array parsing in a reused thread buffer.
Obsoletes the field-expression PatternProperty overload and matches PatternProperty field names as literals and regexes.
PatternPropertyPropertyGeoJSON serialization now throws BsonSerializationException when an extra member has the same name as a declared member.
BsonSerializationExceptionAutomatic encryption now passes the database name to libmongocrypt as UTF-8 instead of the Windows ANSI code page.
LINQ translation now throws NotSupportedException for dictionary keys, BsonDocument keys and Mql.Field names the server would reinterpret.
NotSupportedExceptionBsonDocumentMql.FieldClient certificate comparison in SslSettings now compares the full certificate SHA-256 hash and private key presence.
SslSettingsFindOneAndReplace now throws ArgumentException when the replacement document's first element name starts with $, matching ReplaceOne.
FindOneAndReplaceReplaceOneArgumentExceptionFixes query filter regex injection via unescaped backslash and bracket in LINQ character-set translation.
Uses exact match for file ID in GridFS delete methods.
Fixes KMS master key exposure via unredacted credential serialization in driver settings string.
Fixes connection-option injection via unescaped settings in the canonical MongoDB URL builder.
Fixes NoSQL injection via array replacement bypassing update shape validation in driver write path.
Fixes NoSQL injection via unquoted constant GroupBy keys in LINQ pipeline translation.
Fixes NoSQL injection via equality-filter simplification of dollar-keyed documents in the LINQ provider.
Fixes NoSQL injection via unescaped dollar-prefixed values in LINQ constant arrays and documents.
Updates SharpCompress to remedy a vulnerability.
SharpCompressUpdates Snappier to fix a security issue.
SnappierDisables TLS renegotiation when possible.
Removes support for TLS 1.0 and 1.1.
TLS1.0TLS1.1Deprecations to plan for
Deprecated1
Deprecates the Hedged Reads options.