
MongoDBDriverMonitoringCommandStartedEvent::getCommand 메서드는 MongoDB Driver Monitoring Command Started Event에서 발생한 명령을 반환하는 메서드입니다. 이 메서드는 명령의 이름, 파라미터, 옵션 등에 대한 정보를 제공합니다.
이 메서드를 사용하는 예제는 다음과 같습니다.
#hostingforum.kr
java
MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(ConnectionString.builder()
.addHost("localhost:27017")
.build())
.build();
MongoClient mongoClient = MongoClients.create(settings);
MongoDatabase database = mongoClient.getDatabase("mydatabase");
MongoCollection collection = database.getCollection("mycollection");
MongoDriverMonitoringCommandStartedEvent event = new MongoDriverMonitoringCommandStartedEvent(collection, "insertOne", new BsonDocument("name", "John"), new BsonDocument("age", 30));
BsonDocument command = event.getCommand();
System.out.println(command);
이 예제에서는 `MongoDriverMonitoringCommandStartedEvent` 객체를 생성하고 `getCommand` 메서드를 호출하여 발생한 명령을 반환합니다. 반환된 명령은 `BsonDocument` 객체로 반환되며, 명령의 이름, 파라미터, 옵션 등에 대한 정보를 제공합니다.
2025-06-23 09:10