Last active
March 19, 2016 12:02
-
-
Save takeshy/5126427 to your computer and use it in GitHub Desktop.
現在の時間から指定された秒より前のISODateを作成して、Mongo Shellで検索しやすくする
This file contains 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
function zp(num){ | |
return(num < 10 ? "0"+num.toString() : num.toString()); | |
} | |
function toISODate(d){ | |
return ISODate(d.getUTCFullYear() + "-" + zp(d.getUTCMonth() + 1) + "-" + zp(d.getUTCDate()) + "T"+zp(d.getUTCHours()) + ":" + zp(d.getUTCMinutes()) + ":" + zp(d.getUTCSeconds())); | |
} | |
function before(n){ | |
return toISODate(new Date(Date.now() - n * 1000)); | |
} | |
//accessコレクションのTimeフィールドのDataが600秒(10分)以内のレコードを検索 | |
//db.access.find({"time":{$gt: before(600)}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment