Created
October 19, 2017 15:53
-
-
Save samkirton/bdec05118ff937dc0e9a1a59ab1d8cfc to your computer and use it in GitHub Desktop.
MongoDB aggregate query that projects the current date without hours, seconds and milliseconds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Podcast.aggregate([ | |
{ | |
$project: { | |
now: new Date() | |
} | |
}, | |
{ | |
$project: { | |
nowDateOnly: { | |
$subtract:[ | |
'$now', { | |
$add: [ | |
{ | |
$multiply: [{$hour: "$now"},3600000] | |
}, | |
{ | |
$multiply: [{$minute: "$now"},60000] | |
}, | |
{ | |
$multiply: [{$second: "$now"},1000] | |
}, | |
{ | |
$millisecond: "$now" | |
} | |
] | |
} | |
] | |
} | |
} | |
}, | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment