From 7137a1a24e8bd7f28122799fef32f343032901f8 Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Mon, 2 Dec 2024 09:27:25 +0100 Subject: [PATCH 1/9] Tests --- .../Search/OperatorSearchDefinitions.cs | 2 + .../Search/SearchDefinitionBuilder.cs | 26 ++++++++++++ .../Search/AtlasSearchTests.cs | 41 ++++++++++++++++++- .../Search/SearchDefinitionBuilderTests.cs | 5 ++- 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs b/src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs index c1ea0f51986..6b44fd01cd6 100644 --- a/src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs +++ b/src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs @@ -145,6 +145,8 @@ private static BsonValue ToBsonValue(TField value) => DateTime v => (BsonDateTime)v, DateTimeOffset v => (BsonDateTime)v.UtcDateTime, ObjectId v => (BsonObjectId)v, + Guid v => new BsonBinaryData(v, GuidRepresentation.Standard), //TODO Check if correct + null => BsonNull.Value, _ => throw new InvalidCastException() }; } diff --git a/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs b/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs index 1b287c33f4c..e1ae0712af7 100644 --- a/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs +++ b/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs @@ -125,6 +125,19 @@ public SearchDefinition Equals( where TField : struct, IComparable => new EqualsSearchDefinition(path, value, score); + /// + /// + /// + /// + /// + /// + /// + public SearchDefinition EqualsNull( + FieldDefinition path, + SearchScoreDefinition score = null) + where TField : IComparable => + new EqualsSearchDefinition(path, (TField)((object)null)!, score); + /// /// Creates a search definition that queries for documents where an indexed field is equal /// to the specified value. @@ -142,6 +155,19 @@ public SearchDefinition Equals( where TField : struct, IComparable => Equals(new ExpressionFieldDefinition(path), value, score); + /// + /// + /// + /// + /// + /// + /// + public SearchDefinition EqualsNull( + Expression> path, + SearchScoreDefinition score = null) + where TField : IComparable => + EqualsNull(new ExpressionFieldDefinition(path), score); + /// /// Creates a search definition that tests if a path to a specified indexed field name /// exists in a document. diff --git a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs index 4bad0e54c38..a385c2ab7d5 100644 --- a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs @@ -23,7 +23,6 @@ using MongoDB.Driver.Core.TestHelpers.Logging; using MongoDB.Driver.GeoJsonObjectModel; using MongoDB.Driver.Search; -using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; using Xunit.Abstractions; @@ -132,6 +131,17 @@ public void EmbeddedDocument() } } + [Fact] + public void Equals() + { + var result = SearchSingle( + Builders.Search.Compound().Must( + Builders.Search.Text(x => x.Body, "life, liberty, and the pursuit of happiness"), + Builders.Search.Exists(x => x.Title))); + + result.Title.Should().Be("Declaration of Independence"); + } + [Fact] public void Exists() { @@ -532,6 +542,18 @@ public void Sort() result.Title.Should().Be("US Constitution"); } + [Fact] + public void EqualNull() + { + var result = GetCompaniesCollection().Aggregate() + .Search(Builders.Search.EqualsNull(c => c.Description)) + .Single(); + + result.Should().NotBeNull(); + + + } + [Fact] public void Sort_MetaSearchScore() { @@ -739,6 +761,10 @@ private IMongoCollection GetEmbeddedMoviesCollection() => _mongoC .GetDatabase("sample_mflix") .GetCollection("embedded_movies"); + private IMongoCollection GetCompaniesCollection() => _mongoClient + .GetDatabase("sample_training") + .GetCollection("companies"); + [BsonIgnoreExtraElements] public class Comment { @@ -850,5 +876,18 @@ public class EmbeddedMovie [BsonElement("score")] public double Score { get; set; } } + + [BsonIgnoreExtraElements] + private class Company + { + [BsonId] + public ObjectId Id { get; set; } + + [BsonElement("name")] + public string Name { get; set; } + + [BsonElement("description")] + public string Description { get; set; } + } } } diff --git a/tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs b/tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs index a618ea49939..bb83ba62565 100644 --- a/tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs @@ -302,7 +302,8 @@ public void Equals_should_render_supported_type( new object[] { (double)1, "1", Exp(p => p.Double), nameof(Person.Double) }, new object[] { DateTime.MinValue, "ISODate(\"0001-01-01T00:00:00Z\")", Exp(p => p.Birthday), "dob" }, new object[] { DateTimeOffset.MaxValue, "ISODate(\"9999-12-31T23:59:59.999Z\")", Exp(p => p.DateTimeOffset), nameof(Person.DateTimeOffset) }, - new object[] { ObjectId.Empty, "{ $oid: '000000000000000000000000' }", Exp(p => p.Id), "_id" } + new object[] { ObjectId.Empty, "{ $oid: '000000000000000000000000' }", Exp(p => p.Id), "_id" }, + new object[] { Guid.Empty, """{ "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAA==", "subType" : "04" } }""", Exp(p => p.Guid), nameof(Person.Guid) }, }; [Theory] @@ -1230,7 +1231,7 @@ public class Person : SimplePerson public float Float { get; set; } public double Double { get; set; } public decimal Decimal { get; set; } - + public Guid Guid { get; set; } public DateTimeOffset DateTimeOffset { get; set; } public TimeSpan TimeSpan { get; set; } From c6d25adffadf4fe3a68d3359ce7ecee5ead02d62 Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Tue, 3 Dec 2024 10:56:36 +0100 Subject: [PATCH 2/9] Some fixes --- .../Search/SearchDefinitionBuilder.cs | 17 ++--------------- .../Search/AtlasSearchTests.cs | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs b/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs index e1ae0712af7..4b817e442f5 100644 --- a/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs +++ b/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs @@ -122,7 +122,7 @@ public SearchDefinition Equals( FieldDefinition path, TField value, SearchScoreDefinition score = null) - where TField : struct, IComparable => + where TField : IComparable => new EqualsSearchDefinition(path, value, score); /// @@ -152,21 +152,8 @@ public SearchDefinition Equals( Expression> path, TField value, SearchScoreDefinition score = null) - where TField : struct, IComparable => - Equals(new ExpressionFieldDefinition(path), value, score); - - /// - /// - /// - /// - /// - /// - /// - public SearchDefinition EqualsNull( - Expression> path, - SearchScoreDefinition score = null) where TField : IComparable => - EqualsNull(new ExpressionFieldDefinition(path), score); + Equals(new ExpressionFieldDefinition(path), value, score); /// /// Creates a search definition that tests if a path to a specified indexed field name diff --git a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs index a385c2ab7d5..2284463aa01 100644 --- a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs @@ -546,12 +546,21 @@ public void Sort() public void EqualNull() { var result = GetCompaniesCollection().Aggregate() - .Search(Builders.Search.EqualsNull(c => c.Description)) + .Search(Builders.Search.Equals(c => c.Description, null)) .Single(); result.Should().NotBeNull(); + } + [Fact] + public void EqualGuid() + { + var result = GetCompaniesCollection().Aggregate() + .Search(Builders.Search.Equals( c => c.TestGuid, Guid.Empty)) + .Single(); + result.Should().NotBeNull(); + result.Name.Should().Be("test"); } [Fact] @@ -888,6 +897,10 @@ private class Company [BsonElement("description")] public string Description { get; set; } + + [BsonGuidRepresentation(GuidRepresentation.Standard)] + [BsonElement("testGuid")] + public Guid TestGuid { get; set; } } } } From bace726256de058c15269726497e1404fb478b82 Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:05:56 +0100 Subject: [PATCH 3/9] Various corrections --- .../Search/OperatorSearchDefinitions.cs | 3 +- .../Search/SearchDefinitionBuilder.cs | 17 +------- .../Search/AtlasSearchTests.cs | 41 ++++++++++++++----- .../Search/SearchDefinitionBuilderTests.cs | 8 +++- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs b/src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs index 6b44fd01cd6..0253b5d8999 100644 --- a/src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs +++ b/src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs @@ -145,7 +145,7 @@ private static BsonValue ToBsonValue(TField value) => DateTime v => (BsonDateTime)v, DateTimeOffset v => (BsonDateTime)v.UtcDateTime, ObjectId v => (BsonObjectId)v, - Guid v => new BsonBinaryData(v, GuidRepresentation.Standard), //TODO Check if correct + Guid v => new BsonBinaryData(v, GuidRepresentation.Standard), null => BsonNull.Value, _ => throw new InvalidCastException() }; @@ -260,6 +260,7 @@ private static BsonValue ToBsonValue(TField value) => DateTimeOffset v => (BsonDateTime)v.UtcDateTime, string v => (BsonString)v, ObjectId v => (BsonObjectId)v, + Guid v => new BsonBinaryData(v, GuidRepresentation.Standard), _ => throw new InvalidCastException() }; } diff --git a/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs b/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs index 4b817e442f5..d902748c4a5 100644 --- a/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs +++ b/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs @@ -111,7 +111,7 @@ public SearchDefinition EmbeddedDocument( /// /// Creates a search definition that queries for documents where an indexed field is equal /// to the specified value. - /// Supported value types are boolean, numeric, ObjectId and date. + /// Supported value types are null, boolean, numeric, ObjectId, Guid and date. /// /// The type of the field. /// The indexed field to search. @@ -125,23 +125,10 @@ public SearchDefinition Equals( where TField : IComparable => new EqualsSearchDefinition(path, value, score); - /// - /// - /// - /// - /// - /// - /// - public SearchDefinition EqualsNull( - FieldDefinition path, - SearchScoreDefinition score = null) - where TField : IComparable => - new EqualsSearchDefinition(path, (TField)((object)null)!, score); - /// /// Creates a search definition that queries for documents where an indexed field is equal /// to the specified value. - /// Supported value types are boolean, numeric, ObjectId and date. + /// Supported value types are null, boolean, numeric, ObjectId, Guid and date. /// /// The type of the field. /// The indexed field to search. diff --git a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs index 2284463aa01..60622a77539 100644 --- a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs @@ -61,6 +61,7 @@ public AtlasSearchTests(ITestOutputHelper testOutputHelper) : base(testOutputHel RequireEnvironment.Check().EnvironmentVariable("ATLAS_SEARCH_TESTS_ENABLED"); var atlasSearchUri = Environment.GetEnvironmentVariable("ATLAS_SEARCH"); + atlasSearchUri = "mongodb+srv://ferdi:ferdipw@cluster0.3cnvy.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"; Ensure.IsNotNullOrEmpty(atlasSearchUri, nameof(atlasSearchUri)); _mongoClient = new MongoClient(atlasSearchUri); @@ -545,22 +546,40 @@ public void Sort() [Fact] public void EqualNull() { - var result = GetCompaniesCollection().Aggregate() - .Search(Builders.Search.Equals(c => c.Description, null)) + var result = GetLocalTestCollection().Aggregate() + .Search(Builders.Search.Equals(c => c.TestString, null)) .Single(); result.Should().NotBeNull(); + result.Name.Should().Be("testNull"); } [Fact] public void EqualGuid() { - var result = GetCompaniesCollection().Aggregate() - .Search(Builders.Search.Equals( c => c.TestGuid, Guid.Empty)) + var testGuid = Guid.Parse("b52af144-bc97-454f-a578-418a64fa95bf"); + + var result = GetLocalTestCollection().Aggregate() + .Search(Builders.Search.Equals(c => c.TestGuid, testGuid)) .Single(); result.Should().NotBeNull(); - result.Name.Should().Be("test"); + result.Name.Should().Be("test6"); + } + + [Fact] + public void InGuid() + { + var testGuids = new[] + { + Guid.Parse("b52af144-bc97-454f-a578-418a64fa95bf"), Guid.Parse("84da5d44-bc97-454f-a578-418a64fa937a") + }; + + var result = GetLocalTestCollection().Aggregate() + .Search(Builders.Search.In(c => c.TestGuid, testGuids)).ToList(); + + result.Should().HaveCount(2); + result.Select(s => s.Name).Should().BeEquivalentTo(["test6", "test7"]); } [Fact] @@ -770,9 +789,9 @@ private IMongoCollection GetEmbeddedMoviesCollection() => _mongoC .GetDatabase("sample_mflix") .GetCollection("embedded_movies"); - private IMongoCollection GetCompaniesCollection() => _mongoClient - .GetDatabase("sample_training") - .GetCollection("companies"); + private IMongoCollection GetLocalTestCollection() => _mongoClient + .GetDatabase("testDatabase") + .GetCollection("testClasses"); [BsonIgnoreExtraElements] public class Comment @@ -887,7 +906,7 @@ public class EmbeddedMovie } [BsonIgnoreExtraElements] - private class Company + private class TestClass { [BsonId] public ObjectId Id { get; set; } @@ -895,8 +914,8 @@ private class Company [BsonElement("name")] public string Name { get; set; } - [BsonElement("description")] - public string Description { get; set; } + [BsonElement("testString")] + public string TestString { get; set; } [BsonGuidRepresentation(GuidRepresentation.Standard)] [BsonElement("testGuid")] diff --git a/tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs b/tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs index bb83ba62565..2968c98cc41 100644 --- a/tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs @@ -269,7 +269,7 @@ public void Equals_should_render_supported_type( string valueRendered, Expression> fieldExpression, string fieldRendered) - where T : struct, IComparable + where T : IComparable { var subject = CreateSubject(); var subjectTyped = CreateSubject(); @@ -304,11 +304,12 @@ public void Equals_should_render_supported_type( new object[] { DateTimeOffset.MaxValue, "ISODate(\"9999-12-31T23:59:59.999Z\")", Exp(p => p.DateTimeOffset), nameof(Person.DateTimeOffset) }, new object[] { ObjectId.Empty, "{ $oid: '000000000000000000000000' }", Exp(p => p.Id), "_id" }, new object[] { Guid.Empty, """{ "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAA==", "subType" : "04" } }""", Exp(p => p.Guid), nameof(Person.Guid) }, + new object[] { null, "null", Exp(p => p.Name), nameof(Person.Name) }, }; [Theory] [MemberData(nameof(EqualsUnsupportedTypesTestData))] - public void Equals_should_throw_on_unsupported_type(T value, Expression> fieldExpression) where T : struct, IComparable + public void Equals_should_throw_on_unsupported_type(T value, Expression> fieldExpression) where T : IComparable { var subject = CreateSubject(); Record.Exception(() => subject.Equals("x", value)).Should().BeOfType(); @@ -544,6 +545,7 @@ public void In_typed( new object[] { new[] { DateTime.MinValue, DateTime.MaxValue }, new[] { "ISODate(\"0001-01-01T00:00:00Z\")", "ISODate(\"9999-12-31T23:59:59.999Z\")" }, Exp(p => p.Birthday), "dob" }, new object[] { new[] { DateTimeOffset.MinValue, DateTimeOffset.MaxValue }, new[] { "ISODate(\"0001-01-01T00:00:00Z\")", "ISODate(\"9999-12-31T23:59:59.999Z\")" }, Exp(p => p.DateTimeOffset), nameof(Person.DateTimeOffset)}, new object[] { new[] { ObjectId.Empty, ObjectId.Parse("4d0ce088e447ad08b4721a37") }, new[] { "{ $oid: '000000000000000000000000' }", "{ $oid: '4d0ce088e447ad08b4721a37' }" }, Exp(p => p.Id), "_id" }, + new object[] { new[] { Guid.Empty, Guid.Parse("b52af144-bc97-454f-a578-418a64fa95bf") }, new[] { """{ "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAA==", "subType" : "04" } }""", """{ "$binary" : { "base64" : "tSrxRLyXRU+leEGKZPqVvw==", "subType" : "04" } }""" }, Exp(p => p.Guid), nameof(Person.Guid) }, new object[] { new object[] { (byte)1, (short)2, (int)3 }, new[] { "1", "2", "3" }, Exp(p => p.Object), nameof(Person.Object) } }; @@ -1251,6 +1253,8 @@ public class Person : SimplePerson public bool Retired { get; set; } public object Object { get; set; } + + public string Name { get; set; } } public class Family From eb81ec128e05b30f6462ff2bc5f346942dc8b5c1 Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:26:44 +0100 Subject: [PATCH 4/9] Removed link --- tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs index 60622a77539..f201ea206a6 100644 --- a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs @@ -61,7 +61,6 @@ public AtlasSearchTests(ITestOutputHelper testOutputHelper) : base(testOutputHel RequireEnvironment.Check().EnvironmentVariable("ATLAS_SEARCH_TESTS_ENABLED"); var atlasSearchUri = Environment.GetEnvironmentVariable("ATLAS_SEARCH"); - atlasSearchUri = "mongodb+srv://ferdi:ferdipw@cluster0.3cnvy.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"; Ensure.IsNotNullOrEmpty(atlasSearchUri, nameof(atlasSearchUri)); _mongoClient = new MongoClient(atlasSearchUri); From 1e52e6552bda994995821392da555f8d71c4d3a3 Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:38:13 +0100 Subject: [PATCH 5/9] Moving things around --- .../Search/AtlasSearchTests.cs | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs index f201ea206a6..1937288d88e 100644 --- a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs @@ -142,6 +142,28 @@ public void Equals() result.Title.Should().Be("Declaration of Independence"); } + [Fact(Skip = "Skipping this until we can run this test on the Atlas Search cluster.")] + public void EqualsGuid() + { + var testGuid = Guid.Parse("b52af144-bc97-454f-a578-418a64fa95bf"); + + var result = GetLocalTestCollection().Aggregate() + .Search(Builders.Search.Equals(c => c.TestGuid, testGuid)) + .Single(); + + result.Name.Should().Be("test6"); + } + + [Fact(Skip = "Skipping this until we can run this test on the Atlas Search cluster.")] + public void EqualsNull() + { + var result = GetLocalTestCollection().Aggregate() + .Search(Builders.Search.Equals(c => c.TestString, null)) + .Single(); + + result.Name.Should().Be("testNull"); + } + [Fact] public void Exists() { @@ -248,6 +270,23 @@ public void In() results[1].Runtime.Should().Be(31); } + [Fact(Skip = "Skipping this until we can run this test on the Atlas Search cluster")] + public void InGuid() + { + var testGuids = new[] + { + Guid.Parse("b52af144-bc97-454f-a578-418a64fa95bf"), Guid.Parse("84da5d44-bc97-454f-a578-418a64fa937a") + }; + + var result = GetLocalTestCollection().Aggregate() + .Search(Builders.Search.In(c => c.TestGuid, testGuids)) + .Limit(10) + .ToList(); + + result.Should().HaveCount(2); + result.Select(s => s.Name).Should().BeEquivalentTo(["test6", "test7"]); + } + [Fact] public void MoreLikeThis() { @@ -542,45 +581,6 @@ public void Sort() result.Title.Should().Be("US Constitution"); } - [Fact] - public void EqualNull() - { - var result = GetLocalTestCollection().Aggregate() - .Search(Builders.Search.Equals(c => c.TestString, null)) - .Single(); - - result.Should().NotBeNull(); - result.Name.Should().Be("testNull"); - } - - [Fact] - public void EqualGuid() - { - var testGuid = Guid.Parse("b52af144-bc97-454f-a578-418a64fa95bf"); - - var result = GetLocalTestCollection().Aggregate() - .Search(Builders.Search.Equals(c => c.TestGuid, testGuid)) - .Single(); - - result.Should().NotBeNull(); - result.Name.Should().Be("test6"); - } - - [Fact] - public void InGuid() - { - var testGuids = new[] - { - Guid.Parse("b52af144-bc97-454f-a578-418a64fa95bf"), Guid.Parse("84da5d44-bc97-454f-a578-418a64fa937a") - }; - - var result = GetLocalTestCollection().Aggregate() - .Search(Builders.Search.In(c => c.TestGuid, testGuids)).ToList(); - - result.Should().HaveCount(2); - result.Select(s => s.Name).Should().BeEquivalentTo(["test6", "test7"]); - } - [Fact] public void Sort_MetaSearchScore() { From 9ac825d61eac905731694970427c8236406b3b0c Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:39:16 +0100 Subject: [PATCH 6/9] Correction --- tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs index 1937288d88e..b9e76b912ae 100644 --- a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs @@ -131,17 +131,6 @@ public void EmbeddedDocument() } } - [Fact] - public void Equals() - { - var result = SearchSingle( - Builders.Search.Compound().Must( - Builders.Search.Text(x => x.Body, "life, liberty, and the pursuit of happiness"), - Builders.Search.Exists(x => x.Title))); - - result.Title.Should().Be("Declaration of Independence"); - } - [Fact(Skip = "Skipping this until we can run this test on the Atlas Search cluster.")] public void EqualsGuid() { From 58cb3519ddc100c565f18f408082647a6d6e9c44 Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:41:28 +0100 Subject: [PATCH 7/9] Added comment --- tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs index b9e76b912ae..06bf30ee63b 100644 --- a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs @@ -777,6 +777,7 @@ private IMongoCollection GetEmbeddedMoviesCollection() => _mongoC .GetDatabase("sample_mflix") .GetCollection("embedded_movies"); + // This has been used to run some tests locally that still cannot be run on the common Atlas Search cluster private IMongoCollection GetLocalTestCollection() => _mongoClient .GetDatabase("testDatabase") .GetCollection("testClasses"); From 11c89acbd4ee5cbc89113910058316e51f4cbbcf Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:49:13 +0100 Subject: [PATCH 8/9] Corrected doc and removed constraint --- src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs b/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs index d902748c4a5..de3af6ab59b 100644 --- a/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs +++ b/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs @@ -121,8 +121,7 @@ public SearchDefinition EmbeddedDocument( public SearchDefinition Equals( FieldDefinition path, TField value, - SearchScoreDefinition score = null) - where TField : IComparable => + SearchScoreDefinition score = null) => new EqualsSearchDefinition(path, value, score); /// @@ -138,8 +137,7 @@ public SearchDefinition Equals( public SearchDefinition Equals( Expression> path, TField value, - SearchScoreDefinition score = null) - where TField : IComparable => + SearchScoreDefinition score = null) => Equals(new ExpressionFieldDefinition(path), value, score); /// @@ -301,7 +299,7 @@ public SearchDefinition GeoWithin( /// /// Creates a search definition that queries for documents where the value of the field equals to any of specified values. /// - /// The type of the field. Valid types are: boolean, ObjectId, number, date, string. + /// The type of the field. Valid types are: boolean, ObjectId, Guid, number, date, string. /// The indexed field or fields to search. /// Values to compare the field with. /// The score modifier. @@ -315,7 +313,7 @@ public SearchDefinition In( /// /// Creates a search definition that queries for documents where the value of the field equals to any of specified values. /// - /// The type of the field. Valid types are: boolean, ObjectId, number, date, string. + /// The type of the field. Valid types are: boolean, ObjectId, Guid, number, date, string. /// The indexed field or fields to search. /// Values to compare the field with. /// The score modifier. From 409121129c67c743878da5297fa481c694cb49fa Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Wed, 4 Dec 2024 19:30:59 +0100 Subject: [PATCH 9/9] Corrections --- .../Search/AtlasSearchTests.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs index 06bf30ee63b..7649e57b967 100644 --- a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs @@ -131,22 +131,22 @@ public void EmbeddedDocument() } } - [Fact(Skip = "Skipping this until we can run this test on the Atlas Search cluster.")] + [Fact] public void EqualsGuid() { var testGuid = Guid.Parse("b52af144-bc97-454f-a578-418a64fa95bf"); - var result = GetLocalTestCollection().Aggregate() + var result = GetExtraTestsCollection().Aggregate() .Search(Builders.Search.Equals(c => c.TestGuid, testGuid)) .Single(); result.Name.Should().Be("test6"); } - [Fact(Skip = "Skipping this until we can run this test on the Atlas Search cluster.")] + [Fact] public void EqualsNull() { - var result = GetLocalTestCollection().Aggregate() + var result = GetExtraTestsCollection().Aggregate() .Search(Builders.Search.Equals(c => c.TestString, null)) .Single(); @@ -259,7 +259,7 @@ public void In() results[1].Runtime.Should().Be(31); } - [Fact(Skip = "Skipping this until we can run this test on the Atlas Search cluster")] + [Fact] public void InGuid() { var testGuids = new[] @@ -267,7 +267,7 @@ public void InGuid() Guid.Parse("b52af144-bc97-454f-a578-418a64fa95bf"), Guid.Parse("84da5d44-bc97-454f-a578-418a64fa937a") }; - var result = GetLocalTestCollection().Aggregate() + var result = GetExtraTestsCollection().Aggregate() .Search(Builders.Search.In(c => c.TestGuid, testGuids)) .Limit(10) .ToList(); @@ -777,9 +777,8 @@ private IMongoCollection GetEmbeddedMoviesCollection() => _mongoC .GetDatabase("sample_mflix") .GetCollection("embedded_movies"); - // This has been used to run some tests locally that still cannot be run on the common Atlas Search cluster - private IMongoCollection GetLocalTestCollection() => _mongoClient - .GetDatabase("testDatabase") + private IMongoCollection GetExtraTestsCollection() => _mongoClient + .GetDatabase("csharpExtraTests") .GetCollection("testClasses"); [BsonIgnoreExtraElements]