I'm trying to run a script in Robo 3T 1.2.1 which used to work long time ago:
var cursor = db.getCollection('logs').aggregate([
{ $group: { _id: "$userId", count: { $sum: 1 } } },
{ $lookup: { from:"users", localField:"_id", foreignField:"_id", as:"user" } },
{ $sort: { count: -1 } }
]);
for (var i = 1; i <= 250; i++) {
current = cursor.next()
print(current["_id"].toString())
print(current["user"][0]["currentName"])
print(current["count"])
}
But it returned an error:
Error:
Assert: command failed: {
"errmsg" : "exception: Unrecognized pipeline stage name: '$lookup'",
"code" : 16436,
"ok" : 0
} : aggregate failed
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1319:5
DBCollection.prototype.aggregate@:1:355
@(shell):1:14
$ mongo --version returned MongoDB shell version: 2.6.12 on the server. Does anyone know what's wrong?
Edit 1: This script used to return the users who have lots of logs, does anyone know if there is an easy way to rewrite it without $lookup?

This is too ancient database. It looks like
$lookupwas introduced in 3.2 server. See here