라이브러리
[PHP] MongoDBDriverMonitoringCommandFailedEvent::getReply - 명령 응답 문서를 반환합니다.
MongoDB Driver Monitoring Command Failed Event
MongoDB Driver Monitoring Command Failed Event는 MongoDB Driver에서 발생하는 이벤트 중 하나입니다. 이 이벤트는 MongoDB와의 통신 중에 오류가 발생했을 때 발생합니다.
MongoDBDriverMonitoringCommandFailedEvent::getReply
`getReply` 메서드는 MongoDB Driver Monitoring Command Failed Event에서 발생한 오류의 응답을 반환합니다. 이 메서드는 `MongoDBDriverExceptionRuntimeException` 객체를 반환합니다.
예제
#hostingforum.kr
php
use MongoDBDriverMonitoringCommandFailedEvent;
use MongoDBDriverMonitoringCommandFailedHandler;
// MongoDB Client 생성
$client = new MongoDBClient('mongodb://localhost:27017');
// Command Failed Event 핸들러 생성
$commandFailedHandler = new class implements CommandFailedHandler {
public function onCommandFailed(CommandFailedEvent $event) {
// Command Failed Event 발생 시 호출되는 메서드
echo "Command Failed Event 발생
";
// getReply 메서드를 사용하여 오류의 응답을 반환
$reply = $event->getReply();
echo "오류의 응답: " . $reply->getMessage() . "
";
}
};
// Command Failed Event 핸들러 등록
$client->getServerList()->addCommandFailedHandler($commandFailedHandler);
// MongoDB에 데이터 삽입
$result = $client->selectDatabase('test')->selectCollection('test')->insertOne(['name' => 'John']);
// MongoDB와의 통신 중 오류가 발생
$result = $client->selectDatabase('test')->selectCollection('test')->insertOne(['name' => 'John']);
// Command Failed Event 발생 시 호출되는 메서드 호출
$commandFailedHandler->onCommandFailed(new CommandFailedEvent('insert', 'test', 'test'));
결과
#hostingforum.kr
Command Failed Event 발생
오류의 응답: E11000 duplicate key error collection: test.test index: _id_ dup key: { : ObjectId('...') }
참고
* MongoDB Driver Monitoring Command Failed Event:
* MongoDB Driver Monitoring Command Failed Handler:
* MongoDB Driver Exception RuntimeException:
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.