-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathsp.process.txt
203 lines (170 loc) · 4.61 KB
/
sp.process.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
============
sp.process()
============
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 2
:class: singlecol
Definition
-----------
.. method:: sp.process()
.. versionadded:: 7.0
Creates an ephemeral :atlas:`Stream Processor
</atlas-sp/overview/#mongodb-expression-exp.Stream-Processor>` on
the current :atlas:`Stream Processing Instance
</atlas-sp/overview/#mongodb-expression-exp.Stream-Processing-Instance>`.
Compatibility
-------------
.. include:: /includes/fact-environments-atlas-support-stream-processing-only.rst
Syntax
-----------
The :method:`sp.process()` method has the following
syntax:
.. code-block:: json
sp.process(
[
<pipeline>
],
{
<options>
}
)
Command Fields
---------------------------
``sp.createStreamProcessor()`` takes these fields:
.. list-table::
:header-rows: 1
:widths: 20 20 20 40
* - Field
- Type
- Necessity
- Description
* - ``name``
- string
- Required
- Logical name for the stream processor. This must be unique
within the stream processing instance.
* - ``pipeline``
- array
- Required
- :ref:`Stream aggregation pipeline <stream-aggregation>` you
want to apply to your streaming data.
* - ``options``
- object
- Optional
- Object defining various optional settings for your stream
processor.
* - ``options.dlq``
- object
- Conditional
- Object assigning a
:term:`dead letter queue` for your stream processing instance.
This field is necessary if you define the ``options`` field.
* - ``options.dlq.connectionName``
- string
- Conditional
- Label that identifies a connection in your
connection registry. This connection must reference an
Atlas cluster. This field is necessary if you define the
``options.dlq`` field.
* - ``options.dlq.db``
- string
- Conditional
- Name of an Atlas database on the cluster specified
in ``options.dlq.connectionName``. This field is necessary if
you define the ``options.dlq`` field.
* - ``options.dlq.coll``
- string
- Conditional
- Name of a collection in the database specified in
``options.dlq.db``. This field is necessary if you
define the ``options.dlq`` field.
Behavior
---------------
``sp.process()`` creates an ephemeral, unnamed stream
processor on the current stream processing instance and immediately
initializes it. This stream processor only persists as long as it
runs. If you terminate an ephemeral stream processor, you must create
it again in order to use it.
Access Control
------------------------
The user running ``sp.process()`` must have the
:atlasrole:`atlasAdmin` role.
Example
----------------
The following example creates an ephemeral stream processor
which ingests data from the ``sample_stream_solar`` connection. The
processor excludes all documents where the value of the ``device_id``
field is ``device_8``, passing the rest to a :atlas:`tumbling window
</atlas-sp/overview/#tumbling-windows>` with a 10-second
duration. Each window groups the documents it receives, then returns
various useful statistics of each group. The stream processor then
merges these records to ``solar_db.solar_coll`` over the ``mongodb1``
connection.
.. code-block:: json
:copyable: true
sp.process(
[
{
$source: {
connectionName: 'sample_stream_solar',
timeField: {
$dateFromString: {
dateString: '$timestamp'
}
}
}
},
{
$match: {
$expr: {
$ne: [
"$device_id",
"device_8"
]
}
}
},
{
$tumblingWindow: {
interval: {
size: NumberInt(10),
unit: "second"
},
"pipeline": [
{
$group: {
"_id": { "device_id": "$device_id" },
"max_temp": { $max: "$obs.temp" },
"max_watts": { $max: "$obs.watts" },
"min_watts": { $min: "$obs.watts" },
"avg_watts": { $avg: "$obs.watts" },
"median_watts": {
$median: {
input: "$obs.watts",
method: "approximate"
}
}
}
}
]
}
},
{
$merge: {
into: {
connectionName: "mongodb1",
db: "solar_db",
coll: "solar_coll"
},
on: ["_id"]
}
}
]
)
Learn More
------------------
- :atlas:`Stream Aggregation </atlas-sp/stream-aggregation>`
- :atlas:`Manage Stream Processors </atlas-sp/manage-stream-processor>`