在我的Mongo聚合查询中,我试图使用在另一个正在创建的新字段中创建的新字段。
我在下面做了一个示例。我尝试创建的新字段是whateverThePreviousOneWas
,在此示例中,该字段应与新创建的funnyWord
相同。但是,Mongo似乎完全忽略了它。
Here's the Mongo playground link
代码如下:
db.collection.aggregate([
{
$addFields: {
funnyWord: "fooey",
whateverThePreviousOneWas: "fooey"
}
},
{
$project: {
funnyWord: 1,
whateverThePreviousOneWas: 1
}
}
])
预期产量
[
{
"_id": 0,
"funnyWord": "fooey",
whateverThePreviousOneWas: 'fooey'
},
{
"_id": 1,
"funnyWord": "fooey",
whateverThePreviousOneWas: 'fooey'
},
...
]
实际输出
[
{
"_id": 0,
"funnyWord": "fooey"
},
{
"_id": 1,
"funnyWord": "fooey"
},
...
]