Skip to content

Commit

Permalink
merge mongo driver 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Dec 5, 2024
2 parents 4b86345 + 1a43b71 commit a17b716
Show file tree
Hide file tree
Showing 117 changed files with 1,852 additions and 506 deletions.
21 changes: 21 additions & 0 deletions Release Notes/Release Notes v3.1.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# .NET Driver Version 3.1.0 Release Notes

This is the general availability release for the 3.1.0 version of the driver.

The main new features in 3.1.0 include:

+ Support token field type and array field expressions with Atlas Search builders for equals operator - [CSHARP-4926](https://jira.mongodb.org/browse/CSHARP-4926)
+ Support `SearchIndexType` option when creating Atlas Search indexes - [CSHARP-4960](https://jira.mongodb.org/browse/CSHARP-4960)
+ Support for valid SRV hostnames with less than 3 parts - [CSHARP-5200](https://jira.mongodb.org/browse/CSHARP-5200)
+ Support for search sequential pagination - [CSHARP-5420](https://jira.mongodb.org/browse/CSHARP-5420)
+ Support for Mql methods: `Exists`, `IsMissing` and `IsNullOrMissing` in filters when possible - [CSHARP-5427](https://jira.mongodb.org/browse/CSHARP-5427)
+ Support for Exact Vector Search (ENN) - [CSHARP-5212](https://jira.mongodb.org/browse/CSHARP-5212)
+ Allow sort option to be supplied to update commands (updateOne, etc.) - [CSHARP-5201](https://jira.mongodb.org/browse/CSHARP-5201)
+ Disabled TLS renegotiation when possible - [CSHARP-2843](https://jira.mongodb.org/browse/CSHARP-2843)
+ Fix a bug in discriminator convention inheritance - [CSHARP-5349](https://jira.mongodb.org/browse/CSHARP-5349)
+ New Serializers for ImmutableArray and other immutable collections - [CSHARP-5335](https://jira.mongodb.org/browse/CSHARP-5335)
+ Minor bug fixes and improvements.

The full list of issues resolved in this release is available at [CSHARP JIRA project](https://jira.mongodb.org/issues/?jql=project%20%3D%20CSHARP%20AND%20fixVersion%20%3D%203.1.0%20ORDER%20BY%20key%20ASC).

Documentation on the .NET driver can be found [here](https://www.mongodb.com/docs/drivers/csharp/v3.1/).
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Task("TestServerlessNet60").IsDependentOn("TestServerless");
Task("TestLibMongoCrypt")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/MongoDB.Libmongocrypt.Tests.csproj"),
items: GetFiles("./**/MongoDB.Driver.Encryption.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) => RunTests(buildConfig, testProject));

Task("TestLoadBalanced")
Expand Down
2 changes: 1 addition & 1 deletion purls.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pkg:nuget/MongoDB.Libmongocrypt@1.10.0
pkg:github/mongodb/libmongocrypt@1.11.0
19 changes: 10 additions & 9 deletions sbom.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
{
"components": [
{
"bom-ref": "pkg:nuget/MongoDB.Libmongocrypt@1.10.0",
"bom-ref": "pkg:github/mongodb/libmongocrypt@1.11.0",
"externalReferences": [
{
"type": "distribution",
"url": "https://www.nuget.org/api/v2/package/MongoDB.Libmongocrypt/1.10.0"
"url": "https://github.com/mongodb/libmongocrypt/archive/refs/tags/1.11.0.tar.gz"
},
{
"type": "website",
"url": "https://www.nuget.org/packages/MongoDB.Libmongocrypt/1.10.0"
"url": "https://github.com/mongodb/libmongocrypt/tree/1.11.0"
}
],
"name": "MongoDB.Libmongocrypt",
"purl": "pkg:nuget/[email protected]",
"group": "mongodb",
"name": "libmongocrypt",
"purl": "pkg:github/mongodb/[email protected]",
"type": "library",
"version": "1.10.0"
"version": "1.11.0"
}
],
"dependencies": [
{
"ref": "pkg:nuget/MongoDB.Libmongocrypt@1.10.0"
"ref": "pkg:github/mongodb/libmongocrypt@1.11.0"
}
],
"metadata": {
"timestamp": "2024-06-27T18:41:56.248350+00:00",
"timestamp": "2024-10-23T18:16:04.113855+00:00",
"tools": [
{
"externalReferences": [
Expand Down Expand Up @@ -67,7 +68,7 @@
}
]
},
"serialNumber": "urn:uuid:cb433355-beb9-4038-8a04-565191eff5c5",
"serialNumber": "urn:uuid:efc73d6e-4f57-43d3-9293-8d676835245d",
"version": 1,
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
"bomFormat": "CycloneDX",
Expand Down
19 changes: 17 additions & 2 deletions src/MongoDB.Bson/ObjectModel/Decimal128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,12 @@ private Decimal128(ulong highBits, ulong lowBits)
/// <param name="value">The value.</param>
public Decimal128(decimal value)
{
#if NET6_0_OR_GREATER
Span<int> bits = stackalloc int[4];
_ = decimal.GetBits(value, bits);
#else
var bits = decimal.GetBits(value);
#endif
var isNegative = (bits[3] & 0x80000000) != 0;
var scale = (short)((bits[3] & 0x00FF0000) >> 16);
var exponent = (short)-scale;
Expand Down Expand Up @@ -1904,7 +1909,12 @@ public int Compare(Decimal128 x, Decimal128 y)
{
var xType = GetDecimal128Type(x);
var yType = GetDecimal128Type(y);
var result = xType.CompareTo(yType);
// .NET Framework lacks some optimizations for enums that would result in boxing and lookup overhead for the default comparer
#if NET6_0_OR_GREATER
var result = Comparer<Decimal128Type>.Default.Compare(xType, yType);
#else
var result = ((int)xType).CompareTo((int)yType);
#endif
if (result == 0 && xType == Decimal128Type.Number)
{
return CompareNumbers(x, y);
Expand All @@ -1928,7 +1938,12 @@ private int CompareNumbers(Decimal128 x, Decimal128 y)
{
var xClass = GetNumberClass(x);
var yClass = GetNumberClass(y);
var result = xClass.CompareTo(yClass);
// .NET Framework lacks some optimizations for enums that would result in boxing and lookup overhead for the default comparer
#if NET6_0_OR_GREATER
var result = Comparer<NumberClass>.Default.Compare(xClass, yClass);
#else
var result = ((int)xClass).CompareTo((int)yClass);
#endif
if (result == 0)
{
if (xClass == NumberClass.Negative)
Expand Down
34 changes: 31 additions & 3 deletions src/MongoDB.Bson/Serialization/BsonClassMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,12 +1323,40 @@ internal IDiscriminatorConvention GetDiscriminatorConvention()
var discriminatorConvention = _discriminatorConvention;
if (discriminatorConvention == null)
{
// it's possible but harmless for multiple threads to do the field initialization at the same time
// discriminatorConvention = _hasRootClass ? StandardDiscriminatorConvention.Hierarchical : StandardDiscriminatorConvention.Scalar;
discriminatorConvention = BsonSerializer.LookupDiscriminatorConvention(_classType);
// it's possible but harmless for multiple threads to do the discriminator convention lookukp at the same time
discriminatorConvention = LookupDiscriminatorConvention();
_discriminatorConvention = discriminatorConvention;
}
return discriminatorConvention;

IDiscriminatorConvention LookupDiscriminatorConvention()
{
var classMap = this;
while (classMap != null)
{
if (classMap._discriminatorConvention != null)
{
return classMap._discriminatorConvention;
}

if (BsonSerializer.IsDiscriminatorConventionRegisteredAtThisLevel(classMap._classType))
{
// in this case LookupDiscriminatorConvention below will find it
break;
}

if (classMap._isRootClass)
{
// in this case auto-register a hierarchical convention for the root class and look it up as usual below
BsonSerializer.GetOrRegisterDiscriminatorConvention(classMap._classType, StandardDiscriminatorConvention.Hierarchical);
break;
}

classMap = classMap._baseClassMap;
}

return BsonSerializer.LookupDiscriminatorConvention(_classType);
}
}

// private methods
Expand Down
45 changes: 45 additions & 0 deletions src/MongoDB.Bson/Serialization/BsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,51 @@ public static object Deserialize(TextReader textReader, Type nominalType, Action
}
}

internal static IDiscriminatorConvention GetOrRegisterDiscriminatorConvention(Type type, IDiscriminatorConvention discriminatorConvention)
{
__configLock.EnterReadLock();
try
{
if (__discriminatorConventions.TryGetValue(type, out var registeredDiscriminatorConvention))
{
return registeredDiscriminatorConvention;
}
}
finally
{
__configLock.ExitReadLock();
}

__configLock.EnterWriteLock();
try
{
if (__discriminatorConventions.TryGetValue(type, out var registeredDiscrimantorConvention))
{
return registeredDiscrimantorConvention;
}

RegisterDiscriminatorConvention(type, discriminatorConvention);
return discriminatorConvention;
}
finally
{
__configLock.ExitWriteLock();
}
}

internal static bool IsDiscriminatorConventionRegisteredAtThisLevel(Type type)
{
__configLock.EnterReadLock();
try
{
return __discriminatorConventions.ContainsKey(type);
}
finally
{
__configLock.ExitReadLock();
}
}

/// <summary>
/// Gets the serializer registry.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
#if NET6_0_OR_GREATER
using System.Collections.Immutable;
#endif
using System.Collections.ObjectModel;
using System.Dynamic;
using System.Linq;
Expand Down Expand Up @@ -43,7 +46,17 @@ static CollectionsSerializationProvider()
{ typeof(ReadOnlyCollection<>), typeof(ReadOnlyCollectionSerializer<>) },
{ typeof(Stack<>), typeof(StackSerializer<>) },
{ typeof(Memory<>), typeof(MemorySerializer<>) },
{ typeof(ReadOnlyMemory<>), typeof(ReadonlyMemorySerializer<>) }
{ typeof(ReadOnlyMemory<>), typeof(ReadonlyMemorySerializer<>) },
#if NET6_0_OR_GREATER
{ typeof(ImmutableArray<>), typeof(ImmutableArraySerializer<>) },
{ typeof(ImmutableList<>), typeof(ImmutableListSerializer<>) },
{ typeof(ImmutableHashSet<>), typeof(ImmutableHashSetSerializer<>) },
{ typeof(ImmutableSortedSet<>), typeof(ImmutableSortedSetSerializer<>) },
{ typeof(ImmutableDictionary<,>), typeof(ImmutableDictionarySerializer<,>) },
{ typeof(ImmutableSortedDictionary<,>), typeof(ImmutableSortedDictionarySerializer<,>) },
{ typeof(ImmutableQueue<>), typeof(ImmutableQueueSerializer<>) },
{ typeof(ImmutableStack<>), typeof(ImmutableStackSerializer<>) }
#endif
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Etherna.MongoDB.Bson.Serialization.Serializers
public sealed class EnumerableInterfaceImplementerSerializer<TValue> :
EnumerableInterfaceImplementerSerializerBase<TValue>,
IChildSerializerConfigurable
where TValue : class, IList, new()
where TValue : IEnumerable, new()
{
// constructors
/// <summary>
Expand Down Expand Up @@ -96,7 +96,7 @@ IBsonSerializer IChildSerializerConfigurable.WithChildSerializer(IBsonSerializer
public sealed class EnumerableInterfaceImplementerSerializer<TValue, TItem> :
EnumerableInterfaceImplementerSerializerBase<TValue, TItem>,
IChildSerializerConfigurable
where TValue : class, IEnumerable<TItem>
where TValue : IEnumerable<TItem>
{
// constructors
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Etherna.MongoDB.Bson.Serialization.Serializers
/// Represents a serializer for enumerable values.
/// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam>
public abstract class EnumerableInterfaceImplementerSerializerBase<TValue> : EnumerableSerializerBase<TValue>, IBsonArraySerializer where TValue : class, IEnumerable
public abstract class EnumerableInterfaceImplementerSerializerBase<TValue> : EnumerableSerializerBase<TValue> where TValue : IEnumerable
{
// constructors
/// <summary>
Expand Down Expand Up @@ -87,7 +87,7 @@ protected override TValue FinalizeResult(object accumulator)
/// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <typeparam name="TItem">The type of the items.</typeparam>
public abstract class EnumerableInterfaceImplementerSerializerBase<TValue, TItem> : EnumerableSerializerBase<TValue, TItem>, IBsonArraySerializer where TValue : class, IEnumerable<TItem>
public abstract class EnumerableInterfaceImplementerSerializerBase<TValue, TItem> : EnumerableSerializerBase<TValue, TItem> where TValue : IEnumerable<TItem>
{
// constructors
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Etherna.MongoDB.Bson.Serialization.Serializers
/// Represents a base serializer for enumerable values.
/// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam>
public abstract class EnumerableSerializerBase<TValue> : SerializerBase<TValue>, IBsonArraySerializer where TValue : class, IEnumerable
public abstract class EnumerableSerializerBase<TValue> : SerializerBase<TValue>, IBsonArraySerializer where TValue : IEnumerable
{
// private fields
private readonly IDiscriminatorConvention _discriminatorConvention = new ScalarDiscriminatorConvention("_t");
Expand Down Expand Up @@ -93,8 +93,12 @@ public override TValue Deserialize(BsonDeserializationContext context, BsonDeser
switch (bsonType)
{
case BsonType.Null:
if (typeof(TValue).IsValueType)
{
throw new FormatException($"Cannot deserialize a null value into a value type (type: {BsonUtils.GetFriendlyTypeName(typeof(TValue))}).");
}
bsonReader.ReadNull();
return null;
return default;

case BsonType.Array:
bsonReader.ReadStartArray();
Expand Down Expand Up @@ -219,7 +223,7 @@ public override void Serialize(BsonSerializationContext context, BsonSerializati
/// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <typeparam name="TItem">The type of the items.</typeparam>
public abstract class EnumerableSerializerBase<TValue, TItem> : SerializerBase<TValue>, IBsonArraySerializer where TValue : class, IEnumerable<TItem>
public abstract class EnumerableSerializerBase<TValue, TItem> : SerializerBase<TValue>, IBsonArraySerializer where TValue : IEnumerable<TItem>
{
// private fields
private readonly IDiscriminatorConvention _discriminatorConvention = new ScalarDiscriminatorConvention("_t");
Expand Down Expand Up @@ -289,8 +293,12 @@ public override TValue Deserialize(BsonDeserializationContext context, BsonDeser
switch (bsonType)
{
case BsonType.Null:
if (typeof(TValue).IsValueType)
{
throw new FormatException($"Cannot deserialize a null value into a value type (type: {BsonUtils.GetFriendlyTypeName(typeof(TValue))}).");
}
bsonReader.ReadNull();
return null;
return default;

case BsonType.Array:
bsonReader.ReadStartArray();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#if NET6_0_OR_GREATER
using System.Collections.Immutable;

namespace Etherna.MongoDB.Bson.Serialization.Serializers
{
/// <summary>
/// Represents a serializer for ImmutableArrays.
/// </summary>
/// <typeparam name="T">The type of element stored by the collection.</typeparam>
public class ImmutableArraySerializer<T>: EnumerableInterfaceImplementerSerializerBase<ImmutableArray<T>, T>
{
/// <inheritdoc/>
protected override object CreateAccumulator()
{
return ImmutableArray.CreateBuilder<T>();
}

/// <inheritdoc/>
protected override ImmutableArray<T> FinalizeResult(object accumulator)
{
return ((ImmutableArray<T>.Builder)accumulator).ToImmutable();
}
}
}
#endif
Loading

0 comments on commit a17b716

Please sign in to comment.