chai-backend icon indicating copy to clipboard operation
chai-backend copied to clipboard

reference issue

Open OkamiSan45 opened this issue 1 year ago • 0 comments

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

OkamiSan45 avatar Jan 09 '24 11:01 OkamiSan45