【问题标题】:Unrecognized pipeline stage name: '$concat'无法识别的管道阶段名称:'$concat'
【发布时间】:2016-09-08 17:56:08
【问题描述】:

我正在使用:

db.version()

3.2.3

版本()

3.2.0-17-gde480c0

db.getCollection('events').aggregate([
    { $concat: [ "$element", " - ", "$Eventtype" ] }
])

给我以下错误:

"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"

我在这里做错了什么?

【问题讨论】:

    标签: mongodb aggregation-framework


    【解决方案1】:

    您正在使用 $concat 作为聚合管道中的管道阶段。

    有关阶段列表,请参阅here

    $concat 用作字符串修饰符来连接结果。

    有关示例,请参阅 here

    他们倾向于在示例中的 $project 管道阶段使用 $concat 将文档的两个值合并为一个。

    例如:

    { $project: { itemDescription: { $concat: [ "$item", " - ", "$description" ] } } }
    

    在你的情况下,它可能看起来像......

    { $project: { event: { $concat: [ "$element", " - ", "$Eventtype" ] } } }
    

    【讨论】:

    • 远非如此。在我看来,聚合是 MongoDB 中最复杂的部分。它有很多内容,而且对语法错误非常无情。知道在哪里寻找和寻找什么是最重要的战斗。 (直到我看到你的问题,我才知道 $concat 运算符)
    猜你喜欢
    • 2021-02-10
    • 2019-09-01
    • 2020-10-07
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 1970-01-01
    相关资源
    最近更新 更多