정의
The $function expression specifies a custom JavaScript function that you can define to run JavaScript code on each document in the stream.
중요
$function 기본적으로 비활성화되어 있습니다. MongoDB 지원팀에 문의하여 이 단계를 사용하기 전에 프로젝트에 대해 기능 플래그를 활성화하십시오.
구문
The $function operator has the following syntax:
{ $function: { body: <code>, args: <array expression>, lang: "js" } }
필드 | 유형 | 설명 |
|---|---|---|
문자열 또는 코드 | 함수 정의입니다. 함수 정의를 BSON 유형 코드나 문자열로 지정할 수 있습니다. lang도 함께 참조하세요.
or
| |
배열 | Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array 배열 요소는 코드를 포함한 모든 BSON types일 수 있습니다. 2예시: $where의 대안을 참조하세요. | |
문자열 | The language used in the body. You must specify |
행동
The $function expression runs the specified function on each document in the stream. The function can take arguments from the document or from the args array.
The function can return any BSON type, including an array or a Code type. The returned value is used as the output of the $function expression.