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
In Spring Data JPA, we have @GeneratedValue to create an auto-incrementing ID for our entity. However, Spring Data MongoDB does not support it. Currently there is a hacky approach to support this [1] by creating another collection that stores a sequence number.
This feature can be useful when migrating from a relational database that supports @GeneratedValue to MongoDB where a lot of the application logic has been modelled around the auto-incrementing ID. Also emphasis on the ID being numeric as the data type can be Long/Integer and easily supported, whereas switching to @Id in a @Document would mean a hexadecimal ObjectId of type String which means a lot of type conversions in the codebase.
Thank you for getting in touch. This issue looks similar to the request raised via #1842. Therefore I'll be closing this one as duplicate. Please feel free to leave a comment/upvote on the other ticket or reopen this one if you feel they are not related.
In Spring Data JPA, we have
@GeneratedValue
to create an auto-incrementing ID for our entity. However, Spring Data MongoDB does not support it. Currently there is a hacky approach to support this [1] by creating another collection that stores a sequence number.This feature can be useful when migrating from a relational database that supports
@GeneratedValue
to MongoDB where a lot of the application logic has been modelled around the auto-incrementing ID. Also emphasis on the ID being numeric as the data type can be Long/Integer and easily supported, whereas switching to@Id
in a@Document
would mean a hexadecimal ObjectId of type String which means a lot of type conversions in the codebase.[1] - https://www.baeldung.com/spring-boot-mongodb-auto-generated-field
The text was updated successfully, but these errors were encountered: