What does the Mongo QueryMapper "Could not map xxx. Maybe a fragment in yyy is a simple type" message mean?

Viewed 80

This message started popping up after upgrading Spring Data MongoDB.

2022-07-25 22:27:33.313 INFO 236203 --- [ main] o.s.d.mongodb.core.convert.QueryMapper : Could not map 'Account.user.favorites'. Maybe a fragment in 'User -> String' is considered a simple type. Mapper continues with user.favorites.

The corresponding minimal working example is:

@Document
class Account(val user: User)

@Document
class User(_favorites: MutableList<String>)
{
    @Field("favorites")
    private val _favorites: MutableList<String> = _favorites

    val favorites: List<String>
        get() = _favorites
}

@SpringBootApplication
class DemoApplication(val mongoOperations: MongoOperations): CommandLineRunner
{
    override fun run(vararg args: String?)
    {
        mongoOperations.save(Account(User(mutableListOf("a", "b", "c"))))

        mongoOperations.find(
            Query.query(where("user.favorites").isEqualTo(listOf("a", "b", "c"))),
            Account::class.java)
    }
}

fun main(args: Array<String>)
{
    runApplication<DemoApplication>(*args)
}

It is logged at the INFO level, so apparently it does not mean anything bad, yet the message is logged every time a query is executed.

Also, note that Spring thinks the types in 'Account.user.favorites' are 'User -> String', but in reality they are 'User -> List'.

What are the implications of this message? Isn't this supposed to be a warning at least?

Does my code contai an incorrect type mapping configuration? The reference documentation is not very clear on mapping Kotlin classes.

0 Answers
Related