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.

return handler;
}
#elif NET462
#elif NET462 || NET472
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just do #elif NETFRAMEWORK?

Comment on lines +19 to +41
{
if (value is null)
{
return BsonNull.Value;
}

if (value.GetType().IsArray)
{
if (value is Guid[] guids)
{
return new BsonArray(Array.ConvertAll(guids, x => new BsonBinaryData(x, GuidRepresentation.Standard)));
}

return new BsonArray(value as Array);
}

if (value is Guid guid)
{
return new BsonBinaryData(guid, GuidRepresentation.Standard);
}

return BsonValue.Create(value);
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: am addicted to switch expressions:

Suggested change
{
if (value is null)
{
return BsonNull.Value;
}
if (value.GetType().IsArray)
{
if (value is Guid[] guids)
{
return new BsonArray(Array.ConvertAll(guids, x => new BsonBinaryData(x, GuidRepresentation.Standard)));
}
return new BsonArray(value as Array);
}
if (value is Guid guid)
{
return new BsonBinaryData(guid, GuidRepresentation.Standard);
}
return BsonValue.Create(value);
}
=> value switch
{
null => BsonNull.Value,
Guid guid => new BsonBinaryData(guid, GuidRepresentation.Standard),
Guid[] guids => new BsonArray(Array.ConvertAll(guids, x => new BsonBinaryData(x, GuidRepresentation.Standard))),
Array array => new BsonArray(array),
_ => BsonValue.Create(value)
};

<AssemblyName>Microsoft.SemanticKernel.Connectors.MongoDB</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<TargetFrameworks>net8.0;netstandard2.0;net462</TargetFrameworks>
<TargetFrameworks>net8.0;net472</TargetFrameworks>
Copy link
Member

Choose a reason for hiding this comment

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

Should this also target netstandard2.1, given that MongoDB.Driver targets that? There probably isn't huge value in doing so, but then the MEVD provider is supposed to be a simple layer on top of the driver, so ideally would support whatever the driver supports... Also it's probably pretty trivial to add.

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

3 participants