You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tested with version 3.6.2 and 3.10.1 that this is the case.
If you take a scenario like
abstractclassReportableData(@BsonId valid:Any) {
var metadata:Map<String, Any?> = emptyMap()
var updated:Date=Date()
var dirty:Boolean=false
}
openclassTicket(id:String) : ReportableData(id) {
var title:String?=nullvar status:String?=nullvar opened:Date?=nullvar closed:Date?=null
}
then if you go to save it with something like
val collection = db.getCollection<Ticket>()
.withReadPreference(ReadPreference.primary())
val ticket =Ticket("apple").apply {
title ="Testing"
status ="Closed"
}
collection.save(ticket)
it will work the first time saving the item including the id correctly. The 2nd time you run the program it will error out saying that document with id "apple" already exists.
When you walk through the code in the save it seems that the val id = KMongoUtil.getIdValue(document)
pulls back a null for the id. When you dig into what it is doing you see it goes to a function that does val idProperty = ClassMappingType.findIdProperty(value.javaClass.kotlin)
and that is pulling back
for the idProperty a value correlated to val blah.blah.blah.Ticket.id: kotlin.String
However, the id on the Ticket object doesn't have the @BsonId on it. It should have gone to the parent object and pulled the id from it instead. It clearly works fine when it goes into the insertOne mode and lets the native mongo drivers save the document. It is just that the custom code for identifying the idProperty is not looking for the @BsonId annotated field for its identifier. And even though the Ticket's version of the "id" property is nothing more then a passthrough, it is getting tagged with it.
then the save call works as expected. Looks like the issue is with the logic in trying to find the Id property in that it assumes that "id" field is the id even though there is an annotated bsonid which is the real thing that gets used by the native java mongo driver. This creates for a contradiction of behavior.
The text was updated successfully, but these errors were encountered:
Tested with version 3.6.2 and 3.10.1 that this is the case.
If you take a scenario like
then if you go to save it with something like
it will work the first time saving the item including the id correctly. The 2nd time you run the program it will error out saying that document with id "apple" already exists.
When you walk through the code in the save it seems that the
val id = KMongoUtil.getIdValue(document)
pulls back a null for the id. When you dig into what it is doing you see it goes to a function that does
val idProperty = ClassMappingType.findIdProperty(value.javaClass.kotlin)
and that is pulling back
for the idProperty a value correlated to
val blah.blah.blah.Ticket.id: kotlin.String
However, the id on the Ticket object doesn't have the @BsonId on it. It should have gone to the parent object and pulled the id from it instead. It clearly works fine when it goes into the insertOne mode and lets the native mongo drivers save the document. It is just that the custom code for identifying the idProperty is not looking for the @BsonId annotated field for its identifier. And even though the Ticket's version of the "id" property is nothing more then a passthrough, it is getting tagged with it.
If I change the Ticket to say
then the save call works as expected. Looks like the issue is with the logic in trying to find the Id property in that it assumes that "id" field is the id even though there is an annotated bsonid which is the real thing that gets used by the native java mongo driver. This creates for a contradiction of behavior.
The text was updated successfully, but these errors were encountered: