Docs Menu
Docs Home
/
MongoDB Manual
/ / /

sp.processor.sample()

On this page

  • Definition
  • Syntax
  • Command Fields
  • Behavior
  • Access Control
  • Example
  • Learn More
sp.processor.sample()

Returns arrays of sampled results from a currently running Stream Processor on the current Stream Processing Instance.

You can only invoke this command while connected to a stream processing instance.

This command requires mongosh version ≥ 2.0.

The sp.processor.sample() method has the following syntax:

sp.processor.sample()

sp.processor.sample() takes no fields.

sp.processor.sample() returns arrays of sampled results from the named, currently running stream processor to STDOUT. This command runs continuously until you cancel it using CTRL-C, or until the returned samples cumulatively reach 40 MB.

The user running sp.processor.sample() must have the atlasAdmin role.

The following example shows an expected response from calling sp.solarDemo.sample() to sample from a stream processor called solarDemo:

sp.solarDemo.sample()
{
_id: {
device_id: 'device_5'
},
max_temp: 8,
max_watts: 66,
min_watts: 66,
avg_watts: 66,
median_watts: 66,
_stream_meta: {
windowStartTimestamp: ISODate('2024-03-19T22:09:10.000Z'),
windowEndTimestamp: ISODate('2024-03-19T22:09:20.000Z')
}
}
{
_id: {
device_id: 'device_0'
},
max_temp: 18,
max_watts: 210,
min_watts: 68,
avg_watts: 157,
median_watts: 193,
_stream_meta: {
windowStartTimestamp: ISODate('2024-03-19T22:09:10.000Z'),
windowEndTimestamp: ISODate('2024-03-19T22:09:20.000Z')
}
}
{
_id: {
device_id: 'device_10'
},
max_temp: 21,
max_watts: 128,
min_watts: 4,
avg_watts: 66,
median_watts: 4,
_stream_meta: {
windowStartTimestamp: ISODate('2024-03-19T22:09:10.000Z'),
windowEndTimestamp: ISODate('2024-03-19T22:09:20.000Z')
}
}
{
_id: {
device_id: 'device_9'
},
max_temp: 10,
max_watts: 227,
min_watts: 66,
avg_watts: 131.4,
median_watts: 108,
_stream_meta: {
windowStartTimestamp: ISODate('2024-03-19T22:09:10.000Z'),
windowEndTimestamp: ISODate('2024-03-19T22:09:20.000Z')
}
}

Back

sp.processor.drop()

Next

sp.processor.start()