简体   繁体   中英

java.lang.IllegalStateException: Required identifier property not found for class com.domain.Profile! - Mongo, SpringBoot

I am using SpringBoot with Mongo in my project.

I have a Profile model that looks like this.

@Data
@Document
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Profile {
    private String birthDate;
    private Stirng city;
    private String country;  
}

I can add it to Mongo via postman but when I try to delete it from Mongo by Id I am getting following error.

java.lang.IllegalStateException: Required identifier property not found for class com.domain.Profile!

This is deleteById method.

 @DeleteMapping(value = "/{profileId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> deleteById(@PathVariable String profileId) {
        if (profileRepository.existsById(profileId)) {
            profileRepository.deleteById(profileId);
            return new ResponseEntity<>("Profile properly deleted.",HttpStatus.OK);
        } else {
            return new ResponseEntity<>("Profile not found.", HttpStatus.NOT_FOUND);
        }
    }

I use Postman like this:

在此处输入图片说明

What am I missing here?

Try this,

在此处输入图片说明

where 23 is profileId

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM