英文:
Java Spring MongoDB ORM not deleting file with deleteById(id)
问题
我试图在数据库中删除一个条目
在 MongoDB 中,该条目如下所示:
_id
"11c4ee15-0048-4cc6-8a62-38e40389f2a8"
title
"删除我"
content
"这是第一课"
我正在使用这个存储库:
public interface LessonRepository extends MongoRepository<Lesson, UUID> {
}
为什么这个调用在没有找到 id 的情况下失败:
public void deleteLesson(UUID id) {
lessonRepository.deleteById(id);
}
模型看起来是这样的:
@Data
public class Lesson {
@Id
private String id;
private String title;
private String content;
}
我猜想 id 没有正确定义。但将其定义为 UUID 会得到一个二进制对象?为什么它看起来不像一个 ObjectId?
英文:
I am trying to delete an entry in the database
The entry looks like this in the MongoDB:
> _id
> "11c4ee15-0048-4cc6-8a62-38e40389f2a8"
> title
> "DELETE ME"
> content
> "This is Lesson number 1"
I am using this repository:
public interface LessonRepository extends MongoRepository<Lesson, UUID> {
}
Why does this call fail without finding the id:
public void deleteLesson(UUID id) {
lessonRepository.deleteById(id);
}
The model looks like this:
@Data
public class Lesson {
@Id
private String id;
private String title;
private String content;
}
My guess it that the id is not defined correctly. But defining it as a UUID gives me a binary object? Why doesn't it look like an ObjectId?
答案1
得分: 0
你尝试过修改你的存储库为:
public interface LessonRepository extends MongoRepository<Lesson, String> {
}
英文:
Have you tried modifying your repository to:
public interface LessonRepository extends MongoRepository<Lesson, String> {
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论