chai-backend
chai-backend copied to clipboard
reference issue
it shows the reference error when i am using the $addfeild method of mongo aggeregation pipeline .
to solve that i used the route to not store the feilds as addfeild instead i used the $project and passed the values
// User.find({username}) const channel = await User.aggregate([ { $match: { username: username } }, { $lookup: #{ from: "subscriptions", localField: "_id", foreignField: "channel", as: "subscribers" } }, { $lookup: { from: "subscriptions", localField: "_id", foreignField: "subscriber", as: "subscribedTo" } }, { # $project: { fullName: 1, username: 1, avatar: 1, coverImage: 1, email: 1, subscribersCount: { $size: "$subscribers" }, subscribedCount: { $size: "$subscribedTo" }, isSubscribed: { $cond: { if: { $in: [req.user?._id, "$subscribers.subscriber"] }, then: true, else: false } } } } ]);
then it solved
is there any other way to solve it