Mongoose req.query search not working inside populated document. Help me so that I can search by client name

clientNameSearch returns an empty array even tho there is matching data for the same in database rest all search queries are working fine here is the code

const fetchAllProjects = async (req, res, next) => {
    try {

        let page = parseInt(req.query.page) || 1;
        let limit = 10;
        let offset = (page - 1) * limit;

        const search = req.query.search; //working
        const statusSort = req.query.status; //working
        const site_address = req.query.site_address
        const sortBy = req.query.sortBy;
        const clientNameSearch = req.query.clientNameSearch



        let filter = {};

        if (search) {
            filter["$or"] = [
                { name: { $regex: search, $options: 'i' } },
                { site_code: { $regex: search, $options: 'i' } }
            ]
            console.log("searchh", filter);
        };


        if (statusSort) {
            filter = {
                status: statusSort,
            }
            console.log("statusSort", filter);
        }

        if (search && statusSort) {
            filter["$and"][
                { name: { $regex: search, $options: 'i' } },
                { status: statusSort }
            ]
            console.log("search&&statusSort)", filter);
        };

        if (site_address) {
            filter = {
                site_address: site_address,
            }
            console.log("statusSort", site_address);
        }

        if (clientNameSearch) {
            filter['client_id.name'] = { $regex: clientNameSearch, $options: 'i' };
            console.log("clientNameSearch", filter);
        }


        const allProjects = await Project.find(filter)
            .populate({
                path: 'client_id',
                select: 'name email phone address',
            })
            .populate({
                path: 'managers',
                select: 'first_name last_name email phone',
            })
            .skip(offset)
            .limit(limit)
        // .sort({ first_name: sortBy ? sortBy : 'DESC' })
        // .exec();

        console.log(allProjects);

        const count = await Project.countDocuments(filter);
        console.log("count", count);

        let extras = {
            pageNo: page,
            perPage: limit,
            totalData: count,
            totalPages: Math.ceil(count / limit)
        }

        return response.successResponseData(res, "Projects fetched successfully", allProjects, extras);

    } catch (error) {
        console.log('error', error);
        return res.status(200).json({ error: "Something went wrong" })
    }
}