Ch3 Lab - $group and Accumulators

Without giving away too much about the answer :thinking:, at some point in my pipeline I want to convert a substring I parsed from the documents into an integer. But in the Mongo shell I get the following error:
[js] Error: command failed: {
“operationTime” : Timestamp(1561670380, 3),
“ok” : 0,
“errmsg” : “Unrecognized expression ‘$toInt’”,
“code” : 168,
“codeName” : “InvalidPipelineOperator”,
“$clusterTime” : {
“clusterTime” : Timestamp(1561670380, 3),
“signature” : {
“hash” : BinData(0,“rjZDFNvbMZylcMG9HvAo6mlomgg=”),
“keyId” : NumberLong(“6661714504839069697”)
}
}
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:536:17
assert.commandWorked@src/mongo/shell/assert.js:620:16
DB.prototype._runAggregate@src/mongo/shell/db.js:260:9
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1062:12
@(shell):1:1

I have tried replacing $toInt with a call to $convert and get a similar error. What could be causing this?

I found the answer to my own question. $toInt and $convert exist for mongo 4.0 and higher, but the server is running 3.6 still. I simply removed the part of the expression that converted types, and the aggregation ran successfully.

2 Likes

@Tim_13396

Good work, glad you found it.