Replies: 4 comments 1 reply
-
/cc @FroMage (panache), @loicmathieu (mongodb,panache) |
Beta Was this translation helpful? Give feedback.
-
I talked to @nitinty offline about this first, but since I wasn't sure if this is intended behavior or not, I delegated to opening an issue. If someone wants a reproducer, here it is - https://github.com/xstefank/quarkus-reproducers/tree/main/mongo-id. |
Beta Was this translation helpful? Give feedback.
-
Hi, This should be the correct implementation in case you want a custom ID field that is a String: @BsonId
private String id; However, it seems you field is sometimes a String and sometimes an ObjectId, I'm afraid it cannot work OOTB as we use the PojoCode wich only do 1 <-> 1 mapping of BSON type to Java type. |
Beta Was this translation helpful? Give feedback.
-
@loicmathieu They have ObjectId in Mongo, and they want to pull ID as a String. So the question is if we should be doing ObjectId -> String mapping in the background. I personally also don't think that this is aligned with relational mapping in hibernate and it might be confusing if it differs for mongo. But this is your decision. |
Beta Was this translation helpful? Give feedback.
-
Hi Team,
We are facing an issue with mapping the _id field in our existing MongoDB collections. Our collections already exist, and several of them have a mix of String and ObjectId values for the _id field.
In our previous setup with Spring, we handled this using:
We encounter the following error:
Failed to decode 'TestEntity'. Decoding 'id' errored with: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is OBJECT_ID.
Could you please suggest a workaround or best practice to handle this scenario in Quarkus?
Thanks in advance for your guidance!
Beta Was this translation helpful? Give feedback.
All reactions