I want to join 2 collection:
db.col1.aggregate([
{
$lookup:{
from: "col2", // other table name
localField: "sql_id", // name of users table field
foreignField: "_id", // name of userinfo table field
as: "sql_info" // alias for userinfo table
}
},
{
$project:{
sql_id : 1
}
}
]);
But I get:
: aggregate failed
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:13:14
assert.commandWorked@src/mongo/shell/assert.js:287:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1312:5
@(shell):1:1
2017-02-24T13:05:39.416+0100 E QUERY [thread1] Error: 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:13:14
assert.commandWorked@src/mongo/shell/assert.js:287:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1312:5
@(shell):1:1
col1 document:
{
"_id" : ObjectId("58b00dbc97fce010fd1696b7"),
"dt_ins" : ISODate("2017-02-24T00:00:00.000+0000"),
"sql_id" : "gw8kr1qj01ht3",
"username" : "user",
"executions" : "",
"total_elapsed_sec" : "",
}
col2 document:
{
"_id" : "gw8kr1qj01ht3",
"sql_text" : "select...."
}