org.springframework.data.mapping.model.MappingException: No id property found for object of type

在使用MongotTemplate 进行remove操作时,发生了错误,提示了以下描述

报错提示:org.springframework.data.mapping.model.MappingException: No id property found for object of type

  1. 实体是否指定了id属性

写法多种

@Data
@Document(collection = "xxxx")
public class Entity{
    /**
     * id属性 or--> private String _id;
     */
    private ObjectId id;
    /**
     * 标题
     */
    @Field("post_title")
    private String postTitle;
}
  1. mongoTemplate.remove()是否指定了实体
mongoTemplate.remove(delQuery,Entity.class)

你可能感兴趣的:(mongo,java,mongo,mongoTemplate)