3

How can i make a field in collection incremented automatically ?

@Document
public class Product {

    @Id
    private BigInteger id;

    private String name;

    // need to be auto inc
    private int version;

i use CrudRepository

public interface ProductRepository extends CrudRepository<Product,BigInteger> {
}

i need to increment version in every creation of new product . example : {_id":"56d21eaeb61595413b3b3db7","name":"Prod 1", "version":"1"} {_id":"56d21eaeb61595413b3b3dbb","name":"Prod 2", "version":"2"}

zus
  • 31
  • 1
  • 4
  • Possible duplicate of [How can we create Auto generated field for mongodb using spring boot](https://stackoverflow.com/questions/36448921/how-can-we-create-auto-generated-field-for-mongodb-using-spring-boot) – gstackoverflow Nov 22 '17 at 13:46

0 Answers0