Skip to content

Conversation

@damieng
Copy link
Contributor

@damieng damieng commented Nov 18, 2025

Motivation and Context

Switches the MongoDB Driver to the latest 3.5 release which had a number of breaking changes.

This affects both the MongoDB vector data project and the CosmosMongoDB project.

This fixes #11652 and likely addresses #12707 and partly #10291.

Description

Switches the MongoDB driver to 3.5. Part of the breaking changes is that GUIDs in BSON no longer have a default storage format specified due to the need to switch from the C#-only format to the cross-MongoDB-driver standard format. Setting this is achieved in this PR by way of both a convention for the registry based mode and an alternative to BsonValue.Create in the scenarios where we don't have access to conventions/serialization such as key creation and using the dynamic mapper.

Contribution Checklist

cc @roji

ajcvickers and others added 5 commits November 11, 2025 09:44
This means targetting .NET 4.7.2 for vector data implementations that depend on it.

Supressed warnings about disposal since it doesn't do anything yet.

# Conflicts:
#	dotnet/Directory.Packages.props
@damieng damieng changed the title Switch mongodb to 3 5 Switch MongoDB Driver to v3.5 Nov 18, 2025
@damieng damieng changed the title Switch MongoDB Driver to v3.5 .NET MEVD: Switch MongoDB Driver to v3.5 Nov 18, 2025
@damieng damieng changed the title .NET MEVD: Switch MongoDB Driver to v3.5 .Net: Switch MEVD MongoDB Driver to v3.5 Nov 18, 2025
@damieng damieng marked this pull request as ready for review November 18, 2025 17:12
@damieng damieng requested a review from a team as a code owner November 18, 2025 17:12
@damieng damieng changed the title .Net: Switch MEVD MongoDB Driver to v3.5 .Net: Switch MEVD MongoDB Driver to v3.51 Nov 20, 2025
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see this @damieng, thanks. All looks good, see mainly the question about netstandard2.1 and some nits.

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pinged others for a 2nd review necessary for merging.

@roji roji enabled auto-merge November 27, 2025 19:17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A number of the conformance tests are failing for me, all with a similar error, e.g.
MongoRecordConformanceTests_Guid.GetAsync_WithVectors

Note that these tests have be enabled manually to be run by commenting out the following line in assembly info.
[assembly: DisableTests(Skip = "The MongoDB container is intermittently timing out at startup time blocking prs, so these test should be run manually.")]

Error:

Message: 
MongoDB.Bson.BsonSerializationException : An error occurred while serializing the Id property of class VectorData.ConformanceTests.Models.SimpleRecord`1[[System.Guid, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]: GuidSerializer cannot serialize a Guid when GuidRepresentation is Unspecified.
---- MongoDB.Bson.BsonSerializationException : GuidSerializer cannot serialize a Guid when GuidRepresentation is Unspecified.

Stack Trace: 
BsonClassMapSerializer1.SerializeMember(BsonSerializationContext context, Object obj, BsonMemberMap memberMap) BsonClassMapSerializer1.SerializeClass(BsonSerializationContext context, BsonSerializationArgs args, TClass document)
BsonClassMapSerializer1.Serialize(BsonSerializationContext context, BsonSerializationArgs args, TClass value) BsonExtensionMethods.ToBsonDocument(Object obj, Type nominalType, IBsonSerializer serializer, Action1 configurator, BsonSerializationArgs args)
BsonExtensionMethods.ToBsonDocument[TNominalType](TNominalType obj, IBsonSerializer1 serializer, Action1 configurator, BsonSerializationArgs args)
MongoMapper1.MapFromDataToStorageModel(TRecord dataModel, Int32 recordIndex, IReadOnlyList1[] generatedEmbeddings) line 53
MongoCollection2.UpsertCoreAsync(TRecord record, Int32 recordIndex, IReadOnlyList1[] generatedEmbeddings, CancellationToken cancellationToken) line 270
MongoCollection2.UpsertAsync(IEnumerable1 records, CancellationToken cancellationToken) line 261
VectorStoreCollectionFixture2.SeedAsync() line 52 VectorStoreCollectionFixture2.InitializeAsync() line 41
----- Inner Stack Trace -----
GuidSerializer.Serialize(BsonSerializationContext context, BsonSerializationArgs args, Guid value)
IBsonSerializer.Serialize(BsonSerializationContext context, BsonSerializationArgs args, Object value)
IBsonSerializerExtensions.Serialize(IBsonSerializer serializer, BsonSerializationContext context, Object value)
BsonClassMapSerializer1.SerializeNormalMember(BsonSerializationContext context, Object obj, BsonMemberMap memberMap) BsonClassMapSerializer1.SerializeMember(BsonSerializationContext context, Object obj, BsonMemberMap memberMap)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes made to MongoCollection would need to be applied to CosmosCollection. I don't have authorisation to work on that at my end nor access to a Cosmos instance/emulator to test it with. Sorry.

@zarusz
Copy link

zarusz commented Nov 29, 2025

Great that this is being ported to the latest MDB driver 3.x.

When could we expect a new build to be available?
Currently trying to use the VectorStore abstractions with the SemanticKernel MDB implementation.

Thanks!

Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
@markwallace-microsoft
Copy link
Member

@damieng Can you take a look at the merge conflicts

auto-merge was automatically disabled December 1, 2025 20:41

Head branch was pushed to by a user without write access

@damieng damieng force-pushed the switch-mongodb-to-3-5 branch from 273ed76 to 8daf05a Compare December 1, 2025 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Net: Upgrade MongoDB connector dependency to MongoDB.Driver to v3.x

8 participants