
getDeletedCount 메서드는 MongoDB의 deleteOne() 메서드 또는 deleteMany() 메서드 호출 후에 호출해야 합니다. 이 메서드를 호출하기 전에 delete 메서드를 호출하지 않은 경우, getDeletedCount 메서드는 0을 반환합니다.
deleteOne() 메서드나 deleteMany() 메서드를 호출한 후에 getDeletedCount 메서드를 호출하면, 삭제된 문서의 수를 반환합니다.
예를 들어, 다음 코드는 deleteOne() 메서드를 호출한 후에 getDeletedCount 메서드를 호출하여 삭제된 문서의 수를 반환합니다.
#hostingforum.kr
java
MongoCollection collection = mongoDatabase.getCollection("컬렉션 이름");
Document filter = new Document("필터", "값");
WriteResult result = collection.deleteOne(filter);
int deletedCount = result.getDeletedCount();
이러한 방식으로 getDeletedCount 메서드를 사용하여 삭제된 문서의 수를 구할 수 있습니다.
2025-06-19 15:18