1

I have run the query which is generated by metabase itself:

[
  {
    "$group": {
      "_id": {
        "openedAt~~~month": {
          "$let": {
            "vars": {
              "parts": {
                "$dateToParts": {
                  "date": "$openedAt"
                }
              }
            },
            "in": {
              "$dateFromParts": {
                "year": "$$parts.year",
                "month": "$$parts.month"
              }
            }
          }
        }
      },
      "count": {
        "$sum": 1
      }
    }
  },
  {
    "$sort": {
      "_id": 1
    }
  },
  {
    "$project": {
      "_id": false,
      "openedAt~~~month": "$_id.openedAt~~~month",
      "count": true
    }
  },
  {
    "$sort": {
      "openedAt~~~month": 1
    }
  }
]

where openedAt is an ISODate, ex: 2020-10-27T10:49:49.067Z. but facing error:

Command failed with error 168 (InvalidPipelineOperator): 'Unrecognized expression '$dateToParts'' on server mongo:27017. The full response is { "ok" : 0.0, "errmsg" : "Unrecognized expression '$dateToParts'", "code" : 168, "codeName" : "InvalidPipelineOperator" }

How to solve this issue? I have tried ISODate(), it doesn't work.

ray
  • 11,310
  • 7
  • 18
  • 42
Robin
  • 75
  • 1
  • 5

0 Answers0