Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filterIdToBson doesn't filter id field (only filters '_id' named field) #383

Closed
woodyn1002 opened this issue Nov 12, 2022 · 1 comment
Closed
Labels

Comments

@woodyn1002
Copy link

class FilterIdToBsonTest : FunSpec({
    test("filterIdToBson should filter 'id' property") {
        val id = UUID.randomUUID()

        val bson = KMongoUtil.filterIdToBson(DocumentWithId(id = id, name = "test"), false)

        bson.toBsonDocument().contains("_id") shouldBe false   // failure
    }

    test("filterIdToBson should filter '_id' property") {
        val id = UUID.randomUUID()

        val bson = KMongoUtil.filterIdToBson(DocumentWithUnderscoreId(_id = id, name = "test"), false)

        bson.toBsonDocument().contains("_id") shouldBe false   // success
    }
})

data class DocumentWithId(
    @BsonId val id: UUID,
    val name: String
)

data class DocumentWithUnderscoreId(
    @BsonId val _id: UUID,
    val name: String
)

Because of this issue, the following code throws an exception:

collection.updateOne(DocumentWithId(id = id, name = "test"), upsert())
com.mongodb.MongoWriteException: Write operation error on server localhost:27017. Write error: WriteError{code=66, message='Performing an update on the path '_id' would modify the immutable field '_id'', details={}}.

kmongo version: 4.7.2
jackson version: 2.13.4

@zigzago
Copy link
Member

zigzago commented Nov 13, 2022

Thank you for reporting. Fixed in next release

@zigzago zigzago added the bug label Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants