> db.getCollection("daily_signals").aggregate(
> [
>
> {
> $match: {
> "Stock":{$in: ['SENSOR1','SENSOR2','SENSOR15']},
> $or: [
> {
> "MOSC": {
> $gt: 0.0
> }
> },
> {
> "SHL": {
> $gt: 0.0
> }
> },
> {
> "DDSM": {
> $gt: 0.0
> }
> }
> ],
> },
>
> },
>
> ])
With this aggregation I’m able to query previous signals (where MOSC,SHL,DDSM >1) for each sensor.
However this query returns all signals for each sensor. I would like to get only 2 latest signals of each sensor.(last 2 documents). I tried to limit after match. and also wrap with facet.
Here is an example document:
> {
> "_id" : ObjectId("64adb9af35dbc22c4b376cf8"),
> "Date" : ISODate("2023-07-11T00:00:00.000+0000"),
> "Sensor" : "SENSOR15",
> "MOSC" : NumberInt(66),
> "SHL" : NumberInt(0),
> "DDSM" : NumberInt(0),
> }
Thanks in advance.