Skip to content

Instantly share code, notes, and snippets.

@samkirton
Created October 19, 2017 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samkirton/bdec05118ff937dc0e9a1a59ab1d8cfc to your computer and use it in GitHub Desktop.
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
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