
MongoDB의 WriteResult 객체에서 getInsertedCount 메서드는 WriteResult 객체가 반환하는 결과 중 하나입니다. 이 메서드는 insertOne, insertMany, updateOne, updateMany, replaceOne, deleteOne, deleteMany 메서드의 결과로 반환되는 insertedCount 필드의 값을 반환합니다.
만약 여러 개의 컬렉션에 insertOne 메서드를 사용하여 데이터를 삽입한 경우, 각 컬렉션에 대한 getInsertedCount의 결과는 각 컬렉션에 삽입된 문서의 수를 반환합니다.
getInsertedCount 메서드는 int 형태로 반환되는 것이 아니라 long 형태로 반환됩니다.
예를 들어, 다음과 같은 코드를 작성할 수 있습니다.
#hostingforum.kr
java
MongoCollection collection = db.getCollection("컬렉션명");
WriteResult result = collection.insertOne(new Document("키", "값"));
long insertedCount = result.getInsertedCount();
System.out.println("삽입된 문서의 수 : " + insertedCount);
2025-06-20 01:07