1

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?

1 Answer 1

2

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" ] } } }
1
  • Far from it. Aggregation is in my opinion the most complex part of MongoDB. There's a lot to it, and it's very unforgiving with syntactical errors. Knowing where to look and what to look for is most of the battle. (I didn't know about the $concat operator until I looked at your question)
    – dyouberg
    Sep 8, 2016 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.