I am new to NodeJS
. I have a collection in MongoDB
which holds the Data
shown below
[{
_id: new ObjectId("6180c67a9b414de991a24c43"),
cusDate: '20/11/2021 03:32 AM',
cusName: 'Akila',
cusEmail: 'akila@gmail.com',
__v: 0
},
{
_id: new ObjectId("6180c67a9bt14de991a24c43"),
cusDate: '02/08/2021 08:12 AM',
cusName: 'Booth',
cusEmail: 'booth@gmail.com',
__v: 0
},
{
_id: new ObjectId("u180c67a9b414de991a24c43"),
cusDate: '12/07/2020 11:38 AM',
cusName: 'Sam',
cusEmail: 'sam@gmail.com',
__v: 0
}, {
_id: new ObjectId("61y0c67a9b414de991a24c43"),
cusDate: '22/01/2021 07:42 AM',
cusName: 'Ram',
cusEmail: 'ram@gmail.com',
__v: 0
},
]
I want to find and get the Data from Collection
based on cusDate
.
fromCusDate: 01/06/2020 12:00 AM
toCusDate: 01/03/2021 12:00 PM
Required Output:
[
{
_id: new ObjectId("u180c67a9b414de991a24c43"),
cusDate: '12/07/2020 11:38 AM',
cusName: 'Sam',
cusEmail: 'sam@gmail.com',
__v: 0
}, {
_id: new ObjectId("61y0c67a9b414de991a24c43"),
cusDate: '22/01/2021 07:42 AM',
cusName: 'Ram',
cusEmail: 'ram@gmail.com',
__v: 0
},
]
My cusDate
was in String datatype. The String Date Format was DD/MM/YYYY hh:mm A
Here's the Code i tried,
let getOrdersData = await collection.find({ "cusDate": { "$gte": "01/06/2020 12:00 AM", "$lt": "01/03/2021 12:00 PM" } })
But my date was in String
Datatype in collection
. so i can't get that data.
I don't know to how to get that data. I want to know the Mongoose query to get these data.
let getOrdersMonth = await collection.find({ "cusDate": { "$gte": "01/06/2020 12:00 AM", "$lt": "01/03/2021 12:00 PM" } })
I found this answer. stackoverflow answer. But it is a mongodb query. I need a mongoose query. I searched stackoverflow but can't find any answers. Please Help me with some solutions.