我最近一起使用过Kmongo library和Kotlin,但是我在Kmongo上遇到了问题,但是不确定它是否与库有关。
我正在尝试将数据持久保存到mongo数据库(版本4.2.2)
@Serializable
data class Person(val firstname: String,val lastname: String){
val fullName
get() = "$lastname $firstname"
}
当我插入数据时,我只发送了一个像这样的对象:val person = Person("John","Doe")
但是当我检查我的mongo数据库时
db.persons.find()
> { "_id" : ObjectId("5e2da298159243f9894d3834"),"firstname" : "John","lastname" : "Doe","fullName" : "Doe John" }
如何防止将fullName
保存在数据库中?
编辑:
我尝试在变量上使用@Transient
批注,但是它不起作用,并且收到一条检查消息,内容为:Property does not have backing field which makes it non-serializable and therefore @Transient is redundant