Note
Currently, this functionality is only available in Atlas Stream Processing Instances deployed to AWS cloud.
Definition
The $function
expression specifies a
custom JavaScript function that you can define to run JavaScript code on each document in the stream.
Syntax
The $function
operator has the following syntax:
{ $function: { body: <code>, args: <array expression>, lang: "js" } }
Field | Type | Description |
---|---|---|
String or Code | The function definition. You can specify the function definition as either BSON type Code or String. See also lang.
or
| |
Array | Arguments passed to the function body.
If the body function does not take an
argument, you can specify an empty array The array elements can be any BSON type, including Code. See Example 2: Alternative to $where. | |
String | The language used in the body. You
must specify |
Behavior
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.