小编Hoà*_*Nck的帖子

MongoError:无法识别的管道阶段名称:'$ addFields'

MongoError:无法识别的管道阶段名称:'$ addFields'."mongoose":"^ 4.5.8"我的源代码:

                Post.aggregate(
                    [{
                        $addFields: {
                            userName: { $concat: [ "$author.firstName", " ", "$author.lastName" ] }
                        }
                        //$project: { userName: { $concat: [ "$author.firstName", " ", "$author.lastName" ] } } //this is ok!
                    }],
                    function (err, result) {
                        if (err) {
                            console.log(err);
                            return;
                        }
                        console.log(result);
                    }
                )
Run Code Online (Sandbox Code Playgroud)

发布模型:

let schema = {
id: "post",
properties: {
    content: {type: "string"},
    author: {
        type: "object",
        id: {type: "string"},
        avatar: {type: "string"},
        firstName: {type: "string"},
        lastName: {type: "string"},
        status: {type: "string"}
    }, …
Run Code Online (Sandbox Code Playgroud)

mongodb aggregation-framework

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

aggregation-framework ×1

mongodb ×1