'Need help on searching data using date (from and to)

Good Day!

I need help on how to display data based on the from and to selected/chosen date.

What I have now is the following code:

Back End:

module.exports.getAllFCRequestByYear = (params) => {
    return Request.find({ fc: params.fc, 'createdOn': {'$regex': `.*${params.createdOn}.*`, '$options': 'i'} }).collation({locale:'en', strength: 2}).sort({createdOn:1}).then(result=> {
        return result
    })
}

Front End:

            fetch('http://localhost:4000/api/fcs/get-all-fc-by-title', {
                method: 'POST',
                    headers: {
                    'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        "fc": document.querySelector("#fcID").value,
                        "createdOn": fromDate
                })
            }).then(res => res.json()).then((extracAllFCRequestData) => {
                console.log(extracAllFCRequestData)
            })

What I wanted to know is how to make it from and to instead of searching one value only. Example:

From: 01/01/2022 To: 12/31/2022



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source