0
私は試しています。Mongodbに学生を登録しようとしています。私のクラスで私はemailIdが主キーだと言いましたが、私の意図は学生が同じemailで2回目の登録をしようとしたときです。それはストアではなく、mongodbではなく、エラーは、同じemailIdのデータが更新されます。ここで登録-BlackBoot-MongoDb-プライマリキー新しいデータの置換
は私でしクラスである:ここでは
@Document(collection="StudentData")
public class StudentBean {
private String studentName;
@Id
private String emailId;
private String contactNumber;
private String skillSet;
private String address;
private String password;
は私のコントローラクラスである:ここで
@CrossOrigin("*")
@RequestMapping(method=RequestMethod.POST)
// This Annotation takes care to map specific response to a method with fixed value attribute
public ResponseEntity<String> addUser(@RequestBody StudentBean userBean) throws UserAlreadyExistException{
try {
studentService.addUser(userBean);
}catch(UserAlreadyExistException ue){
throw new UserAlreadyExistException("User Already Exists");
}
return ResponseEntity.ok("User saved successfully");
// ResponseEntity returns message along with HTTP Status.
}
は私のサービスクラスです:
@Override
public StudentBean addUser(StudentBean userBean) throws UserAlreadyExistException{
return studentRepository.save(userBean);
}
は、実際に私はMongoDBのに新しいです、私は主キーがmysqlのように動作することを期待しています。私はエラーをスローするために追加する必要があるものを助けてください。
私はリポジトリメソッドのみを使用しました。つまり、Mongorepositoryから実装するstudentRepositoryです。これは方法ではないということです。 –