Reputation: 145
I am using:
db.version()
3.2.3
version()
3.2.0-17-gde480c0
db.getCollection('events').aggregate([
{ $concat: [ "$element", " - ", "$Eventtype" ] }
])
gives me the following error:
"assert: command failed: {
"ok" : 0,
"errmsg" : "Unrecognized pipeline stage name: '$concat'",
"code" : 16436
} : aggregate failed
_getErrorWithCode@src/mongo/shell/utils.js:23:13
doassert@src/mongo/shell/assert.js:13:14
assert.commandWorked@src/mongo/shell/assert.js:266:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1215:5
@(shell):1:1"
What am I doing wrong here?
Upvotes: 1
Views: 8077
Reputation: 2332
You're using $concat as a pipeline stage in the aggregation pipeline.
See here for a list of the stages.
$concat is used as a string modifier to concatenate the results.
See here for examples.
They tend to use $concat in a $project pipeline stage in the examples to combine two values of a document into one.
For instance:
{ $project: { itemDescription: { $concat: [ "$item", " - ", "$description" ] } } }
in your case it might look something like...
{ $project: { event: { $concat: [ "$element", " - ", "$Eventtype" ] } } }
Upvotes: 2