After further calculations, I have come up with some results that may be of assistance to you.
db.collectionName.aggregate({
"$project": {
"creationTimestamp": {
"$subtract": [{
"$divide": [{
"$subtract": ["$creation_date", new Date("1970-01-01")]
}, 1]
}, {
"$mod": [{
"$divide": [{
"$subtract": ["$creation_date", new Date("1970-01-01")]
}, 1]
}, 1]
}]
},
"days_of_validity": "$days_of_validity",
"todayTimeStamp": {
"$subtract": [new Date().getTime(), 0]
},
"creation_date": "$creation_date"
}
}, {
"$project": {
"dayDifference": {
"$multiply": ["$days_of_validity", 24, 60, 60, 1000]
},
"todayTimeStamp": "$todayTimeStamp",
"creationTimestamp": "$creationTimestamp",
"days_of_validity": "$days_of_validity",
"creation_date": "$creation_date"
}
}, {
"$project": {
"todayAndDaysDifference": {
"$subtract": ["$todayTimeStamp", "$dayDifference"]
},
"creationTimestamp": "$creationTimestamp",
"days_of_validity": "$days_of_validity",
"creation_date": "$creation_date"
}
}, {
"$project": {
"finalDifference": {
"$subtract": ["$creationTimestamp", "$todayAndDaysDifference"]
},
"days_of_validity": "$days_of_validity",
"creation_date": "$creation_date"
}
}, {
"$match": {
"finalDifference": {
"$lt": 0
}
}
}, {
"$project": {
"days_of_validity": "$days_of_validity",
"creation_date": "$creation_date"
}
})