Skip to content

Commit 8522ef3

Browse files
committed
Corrected serializer
1 parent eaa16c4 commit 8522ef3

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

Diff for: src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs

+22-10
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,25 @@ private protected override BsonDocument RenderArguments(
397397
{
398398
if (!_useDefaultSerialization)
399399
{
400-
var min = ToBsonValue(_range.Min);
401-
var max = ToBsonValue(_range.Max);
400+
BsonValue min = null, max = null;
401+
bool minInclusive = false, maxInclusive = false;
402402

403-
return new BsonDocument
403+
if (_range.Min != null)
404404
{
405-
{ _range.IsMinInclusive ? "gte" : "gt", min, min != BsonNull.Value },
406-
{ _range.IsMaxInclusive ? "lte" : "lt", max, max != BsonNull.Value },
405+
min = ToBsonValue(_range.Min.Value);
406+
minInclusive = _range.Min.Inclusive;
407+
}
408+
409+
if (_range.Max != null)
410+
{
411+
max = ToBsonValue(_range.Max.Value);
412+
maxInclusive = _range.Max.Inclusive;
413+
}
414+
415+
return new()
416+
{
417+
{ minInclusive ? "gte" : "gt", min, min != null },
418+
{ maxInclusive ? "lte" : "lt", max, max != null }
407419
};
408420
}
409421

@@ -418,15 +430,15 @@ private protected override BsonDocument RenderArguments(
418430
using var bsonWriter = new BsonDocumentWriter(document);
419431
var context = BsonSerializationContext.CreateRoot(bsonWriter);
420432
bsonWriter.WriteStartDocument();
421-
if (_range.Min is not null)
433+
if (_range.Min != null)
422434
{
423-
bsonWriter.WriteName(_range.IsMinInclusive? "gte" : "gt");
424-
valueSerializer.Serialize(context, _range.Min);
435+
bsonWriter.WriteName(_range.Min.Inclusive? "gte" : "gt");
436+
valueSerializer.Serialize(context, _range.Min.Value);
425437
}
426438
if (_range.Max is not null)
427439
{
428-
bsonWriter.WriteName(_range.IsMaxInclusive? "lte" : "lt");
429-
valueSerializer.Serialize(context, _range.Max);
440+
bsonWriter.WriteName(_range.Max.Inclusive? "lte" : "lt");
441+
valueSerializer.Serialize(context, _range.Max.Value);
430442
}
431443
bsonWriter.WriteEndDocument();
432444

0 commit comments

Comments
 (0)