Reputation: 85
Im using mongo aggregation with mongoose. It works fine, but fails when run in jest.
I get the error:
MongoError: Unrecognized pipeline stage name: '$set'
when using $set inside an aggregation
$set: {
isUsersContent: {
$eq: ["$teacher._id", user._id],
},
}
"mongoose": "^5.3.12", "jest": "^25.1.0",
Upvotes: 7
Views: 8028
Reputation: 3349
The $set
MongoDB Aggregation pipeline stage will work only for MongoDB versions 4.2 and above.
You can use the $addFields
Pipeline stage instead.
$addFields: {
isUsersContent: {
$eq: ["$teacher._id", user._id],
},
}
Note: The
$set
Aggregation Pipeline stage is nothing but an alias$addFields
stage
Upvotes: 12