I want to retrieve data by date and time inside of array from EffectiveDate element.
I saving EffectiveDate by Date.now on Mongodb not with ISO date format.
I want to get result EffectiveDate is not greater than current date and then get the lasted date from list result. My collection data is at the following sample.
"_id": "63a2b0f87a810608e6ca6d95",
"Templates": [
{
"HardwareVer": "minthein@Joseph",
"SoftwareVer": "11111.0",
"RevisionNum": "mtw",
"EffectiveDate": "2022-12-26T08:29:58.470Z",
"WorkTasks": [
"63a70c631dbb68ffa7473be1",
"63aa9a084c60349138c4d5c3"
],
"HasTraveller": true,
"_id": "63a70a691dbb68ffa7473ba8"
},
{
"HardwareVer": "josephwin",
"SoftwareVer": "11111.0",
"RevisionNum": "win",
"EffectiveDate": "2022-12-26T07:29:58.470Z",
"WorkTasks": [],
"HasTraveller": false,
"_id": "63a70b741dbb68ffa7473bbc"
},
{
"HardwareVer": "A333",
"SoftwareVer": "333.0",
"RevisionNum": "221227135521",
"EffectiveDate": "2023-01-27T05:55:09.148Z",
"WorkTasks": [],
"HasTraveller": false,
"_id": "63aa88c96e0a2601d545e52c"
}
],
}
I wish to get result at the follow
{
"_id": "63a2b0f87a810608e6ca6d95",
"Templates": [
{
"HardwareVer": "minthein@Joseph",
"SoftwareVer": "11111.0",
"RevisionNum": "mtw",
"EffectiveDate": "2022-12-26T08:29:58.470Z",
"WorkTasks": [
"63a70c631dbb68ffa7473be1",
"63aa9a084c60349138c4d5c3"
],
"HasTraveller": true,
"_id": "63a70a691dbb68ffa7473ba8"
},
],
} ```
Please help me sir.I had start to learning MongoDB and Nodjs.