In mongoose query, how can I apply query on a virtual data I got from virtual schema using .populate method?

Solution 1:

So, after trying this for some time I got the solution for this problem and i.e.,

    if (userId) {
             const query = {
                 from_user_id: userId,
             };
             const data = await Contact.find(query).populate({
                 path: "request_to_user_information",
                 select: "first_name last_name profile_image country city zip designation company_name",
                 populate: [{ path: "country", modal: "country" }, { path: "city", modal: "city" }],
             }) as IContact[];
             res.send({
                 success: true,
                 message: "data fetched successfully.",
                 data
             });
         }
         else {
             res.status(404).send({
                 success: false,
                 message: "Something went wrong.",
             });
         }