diff --git a/kmongo/src/main/kotlin/org/litote/kmongo/extensions.kt b/kmongo/src/main/kotlin/org/litote/kmongo/extensions.kt index 1b3188a6..0b274b54 100644 --- a/kmongo/src/main/kotlin/org/litote/kmongo/extensions.kt +++ b/kmongo/src/main/kotlin/org/litote/kmongo/extensions.kt @@ -470,7 +470,7 @@ fun MongoCollection.findOneAndDelete(filter: String, options: FindOneAndD * document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be * returned */ -fun MongoCollection.findOneAndReplace(filter: String, replacement: T, options: FindOneAndReplaceOptions = FindOneAndReplaceOptions()): T +fun MongoCollection.findOneAndReplace(filter: String, replacement: T, options: FindOneAndReplaceOptions = FindOneAndReplaceOptions()): T? = findOneAndReplace(toBson(filter), replacement, options) /** @@ -484,7 +484,7 @@ fun MongoCollection.findOneAndReplace(filter: String, replacement: T, opt * document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be * returned */ -fun MongoCollection.findOneAndUpdate(filter: String, update: String, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T +fun MongoCollection.findOneAndUpdate(filter: String, update: String, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T? = findOneAndUpdate(toBson(filter), toBson(update), options) /** diff --git a/kmongo/src/test/kotlin/org/litote/kmongo/issues/Issue34FindOneAndUpdateOrReplaceCouldReturnNull.kt b/kmongo/src/test/kotlin/org/litote/kmongo/issues/Issue34FindOneAndUpdateOrReplaceCouldReturnNull.kt new file mode 100644 index 00000000..c26fda1d --- /dev/null +++ b/kmongo/src/test/kotlin/org/litote/kmongo/issues/Issue34FindOneAndUpdateOrReplaceCouldReturnNull.kt @@ -0,0 +1,26 @@ +package org.litote.kmongo.issues + +import org.junit.Test +import org.litote.kmongo.KMongoBaseTest +import org.litote.kmongo.MongoOperator.set +import org.litote.kmongo.findOneAndReplace +import org.litote.kmongo.findOneAndUpdate +import org.litote.kmongo.model.Friend +import kotlin.test.assertNull + +/** + * + */ +class Issue34FindOneAndUpdateOrReplaceCouldReturnNull : KMongoBaseTest() { + + @Test + fun findOneAndReplaceCouldReturnsNull() { + assertNull(col.findOneAndReplace("{}", Friend("test"))) + } + + @Test + fun findOneAndUpdateCouldReturnsNull() { + assertNull(col.findOneAndUpdate("{}", "{$set:{name:'John'}}")) + } + +} \ No newline at end of file