DateTrunc in aggregate pipeline not recognized for App Services

I am developing a React Web application with a Realm backend written in typescript, that is connected to a cluster of version 5.0.14
I am trying to run a aggregate query on a timeseries collection using the DateTrunc operator;

const aggregateQuery = [
  {
    '$match': {
      'metadata.datapointId': idQuery,
      "time": {
        "$gte": fromTime,
        "$lte": toTime
      }
    }
  }, 
  {
    '$group': {
      '_id': {
        'truncatedDate': {
          '$dateTrunc': {
            'date': '$time',
            'unit': 'hour',
            'binSize': aggregatationIntervalHours
          }
        },
        'name': '$metadata.name'
      },
      'avg': {
        '$avg': '$value'
      },
      'max': {
        '$max': '$value'
      },
      'min': {
        '$min': '$value'
      },
      'count': {
        '$count': {}
      }
    }
  }, {
    '$project': {
      'name': '$_id.name',
      'truncatedDate': '$_id.truncatedDate',
      'avg': '$avg',
      'max': '$max',
      'min': '$min',
      'count': '$count'
    }
  }, {
    '$sort': {
      'truncatedDate': 1
    }
  }
  ]

This query results in the following error

in the logs of the Realm application.

This query works in MongoDB compass, and when using the Node JS MongoDB drivers. I am using realm-web version 2.0.0 (realm-web - npm) in my react application. The same error seems to occur for other operators released in MongoDB 5.0, e.g. dateSubtract, which seems odd since the cluster in question is version 5.0.14

1 Like