$validate
이 페이지의 내용
정의
$validate
단계에서는 스트리밍 문서가 예상 범위, 값 또는 데이터 유형의 스키마를 준수하는지 확인합니다.
구문
$validate
단계에서는 다음 필드가 있는 문서를 사용합니다.
필드 | 유형 | 필요성 | 설명 |
---|---|---|---|
validator | 문서 | 필수 사항 | 사용자 정의 스키마에 대해 수신 메시지의 유효성을 검사하는 데 사용되는 표현식 문서입니다. 다음 쿼리 연산자 를 제외한 모든 연산자를 사용하여 유효성 검사 표현식을 정의할 수 있습니다.
|
validationAction | 문자열 | 옵션 | 메시지가 사용자 정의 스키마를 위반할 때 취할 조치를 지정합니다. 다음 값 중 하나를 지정할 수 있습니다.
|
행동
파이프라인의 어느 점에서나 $source
단계 이후, $emit
또는 $merge
단계 이전에 $validate
를 사용할 수 있습니다.
validationAction
필드에 discard
또는 dlq
옵션을 지정하는 경우 Atlas Stream Processing은 유효성 검사에 실패한 메시지를 다음 형식으로 기록합니다.
{ "t": <datetime>, "s": "<severity-level>", "c": "streams-<job-name>", "ctx": "<processed-pipeline>", "msg": "<message-body>", "attrs": { <result-of-logAttributes-evaluation> }, "tags": <array-of-strings>, "truncated": { <truncation-description> }, "size": <size-of-entry> }
다음 표에서는 로그 항목 필드에 대해 설명합니다.
필드 | 유형 | 설명 |
---|---|---|
attrs | 문서 | $validate 정의의 logAttributes 필드를 평가한 결과가 포함된 문서입니다. 결과는 필드 목록입니다. |
c | 문자열 | 실패가 발생한 특정 Atlas Stream Processing 작업의 이름입니다. |
ctx | 문자열 | 처리 중인 스트리밍 데이터 파이프라인의 이름입니다. |
msg | 문자열 | 유효성 검사에 실패한 메시지 본문입니다. |
Atlas Stream Processing 은 Draft JSON schema 만 4 지원합니다. 또는 그 이전 버전.
유효성 검사기 예제
다음 문서에서는 $and 를 사용하여 논리적 AND 연산을 수행하는 유효성 검사기 표현식의 예를 보여줍니다.
{ $validate: { validator: { $and: [{ $expr: { $ne: [ "$Racer_Name", "Pace Car" ] } }, { $jsonSchema: { required: [ "Racer_Num", "Racer_Name", "lap", "Corner_Num", "timestamp" ], properties: { Racer_Num: { bsonType: "int", description: "'Racer_Num' is the integer number of the race car and is required" }, Racer_Name: { bsonType: "string", description: "'Racer_Name' must be a string and is required" }, lap: { bsonType: "int", minimum: 1, description: "'lap' must be a int and is required" }, Corner_Num: { bsonType: "int", minimum: 1, maximum: 4, description: "'Corner_Num' must be a int between 1 and 4 and is required" }, timestamp: { bsonType: "string", pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{6}$", description: "'timestamp' must be a string matching iso date pattern and is required" } } } }] }, validationAction : "dlq" } }