How we can perform the below given MySQL query in MongoDB preferably in MongoDB-4.0:

SELECT *,ABS(TIME_TO_SEC(TIMEDIFF(now(), datefield))/3600) as hours,
(field1*field2*field2+field3*(1/(ABS(TIME_TO_SEC(TIMEDIFF(now(), datefield))/3600)))) 
as time FROM temp_table

The equivalent MongoDB Query is


Fields to be shown can be added as per the requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.