Generating a shorter ID with MongoDB and spring

137 Views Asked by At

I have an entity that is being saved with a MongoRepository. The class has a property Id annotated with @Id:

public class KCItem {

    @Id
    private String id;

When saved it generates a long id - 5bb390b88ba5b9248ad148ce. These ids will be part of URLs and I'd like them to be shorter (I don't expect to have more than 1 million total items). What would be a better way to either replace Id with a shorter value OR create a second attribute that is the short id?

0

There are 0 best solutions below