I have two date fields in my Mongo
Database and I would like to compare their difference (i.e. their "Age") with a value a value in years.
For example: I would like to find the Pharmacies
that are older than 15 years.
(CurrentDate - EstablishedDate) > 15 (keep in mind the CurrentYear
as it might not be of today's date)
What is the way to do this?
Sample array of documents below:
[
{
"Pharmacy": "a",
"EstablishedDate": ISODate("2006-10-12"),
"CurrentDate": ISODate("2018-07-17"),
"Medicine": [
{
"MedName": "MedA",
"Quantity": 55,
"Type": "Admission"
},
{
"MedName": "MedB",
"Quantity": 34,
"Type": "Admission"
},
{
"MedName": "MedD",
"Quantity": 25,
"Type": "Discharge",
}
]
},
{
"Pharmacy": "b",
"EstablishedDate": ISODate("2015-02-02"),
"CurrentDate": ISODate("2018-07-17"),
"Medicine": [
{
"MedName": "MedB",
"Quantity": 60,
"Type": "Critical"
},
{
"MedName": "MedC",
"Quantity": 34,
"Type": "mild"
}
]
}
]