Spring MongoRepository is updating or upserting instead of inserting

后端 未结 2 1818
甜味超标
甜味超标 2021-02-02 09:24

I\'m using a :

org.springframework.data.mongodb.repository.MongoRepository

I start with an empty DB and create an object with _id = 1234<

2条回答
  •  礼貌的吻别
    2021-02-02 09:59

    the application shall update only when you have @Id annotation for one of the field, after long difficulty had found this

    @Document(collection="bus")
    public class Bus {
    
    //  @Indexed(unique=true, direction=IndexDirection.DESCENDING, dropDups=true)
        @Id
        private String busTitle; 
        private int totalNoOfSeats;
        private int noOfSeatsAvailable; 
        private String busType; 
    }
    

    but somehow I could not use @Indexed(unique=true, direction=IndexDirection.DESCENDING, dropDups=true)

提交回复
热议问题