Skip to content

[FEATURE REQUEST] Support auto-incrementing numeric ID for a document #4597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pk-218 opened this issue Dec 20, 2023 · 1 comment
Closed
Labels
status: duplicate A duplicate of another issue

Comments

@pk-218
Copy link

pk-218 commented Dec 20, 2023

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 20, 2023
@christophstrobl
Copy link
Member

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.

@christophstrobl christophstrobl closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2023
@christophstrobl christophstrobl added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants