gpt4 book ai didi

node.js - 无法测试 mongo 聚合 MongoError : Unrecognized pipeline stage name: '$set'

转载 作者:行者123 更新时间:2023-12-04 00:55:53 27 4
gpt4 key购买 nike

我将 mongo 聚合与 mongoose 一起使用。它工作正常,但在开 Jest 时失败。
我收到错误:

MongoError: Unrecognized pipeline stage name: '$set'
在聚合中使用 $set 时
$set: {
isUsersContent: {
$eq: ["$teacher._id", user._id],
},
}
" Mongoose ": "^5.3.12",
"jest": "^25.1.0",

最佳答案

$set MongoDB 聚合管道阶段仅适用于 MongoDB 4.2 及更高版本。
您可以使用 $addFields管道阶段代替。

$addFields: {
isUsersContent: {
$eq: ["$teacher._id", user._id],
},
}

Note: The $set Aggregation Pipeline stage is nothing but an alias $addFields stage

关于node.js - 无法测试 mongo 聚合 MongoError : Unrecognized pipeline stage name: '$set' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62624944/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com