-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelete.java
More file actions
34 lines (26 loc) · 971 Bytes
/
Delete.java
File metadata and controls
34 lines (26 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.mongodb.quickstart;
import com.mongodb.quickstart.models.Grade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Delete {
@Autowired
private StudentRepository repository;
public void run() {
// Delete one document
Grade grade = repository.findFirstByStudentId(10000d);
if (grade != null) {
repository.delete(grade);
System.out.println("Deleted grade: " + grade);
}
// Find and delete one document
grade = repository.findFirstByStudentId(10002d);
if (grade != null) {
repository.delete(grade);
System.out.println("Deleted grade: " + grade);
}
// Delete many documents
repository.deleteAll(repository.findByStudentIdGreaterThanEqual(10000d));
System.out.println("Deleted all grades with student_id >= 10000.");
}
}