diff --git a/dsl/src/commonMain/kotlin/query/FilterQueryPredicateImpl.kt b/dsl/src/commonMain/kotlin/query/FilterQueryPredicateImpl.kt --- a/dsl/src/commonMain/kotlin/query/FilterQueryPredicateImpl.kt +++ b/dsl/src/commonMain/kotlin/query/FilterQueryPredicateImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.tree.AbstractBsonNode import opensavvy.ktmongo.dsl.tree.AbstractCompoundBsonNode +import opensavvy.ktmongo.dsl.tree.BsonNode /** * Implementation of [FilterQueryPredicate]. @@ -40,6 +41,11 @@ @LowLevelApi private sealed class PredicateBsonNodeNode(context: BsonContext) : AbstractBsonNode(context) + + @LowLevelApi + override fun simplify(children: List): AbstractBsonNode? = + if (children.isEmpty()) null + else this // endregion // region $eq diff --git a/dsl/src/commonTest/kotlin/query/filter/ComparisonFilterTest.kt b/dsl/src/commonTest/kotlin/query/filter/ComparisonFilterTest.kt --- a/dsl/src/commonTest/kotlin/query/filter/ComparisonFilterTest.kt +++ b/dsl/src/commonTest/kotlin/query/filter/ComparisonFilterTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -257,4 +257,25 @@ } } + suite("Optionals variants") { + test($$"$lte not present") { + filter { + User::age gteNotNull null + } shouldBeBson """ + {} + """.trimIndent() + } + + test($$"$lte present") { + filter { + User::age gteNotNull 12 + } shouldBeBson $$""" + { + "age": { + "$gte": 12 + } + } + """.trimIndent() + } + } }