Last active
August 29, 2015 13:56
-
-
Save droustchev/8921021 to your computer and use it in GitHub Desktop.
Small helper functions that enable you to easily clone collections that contain a date in the name (e.g. 'logs_2014-02-01') from one MongoDB instance to another.
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 getDateString (date) { | |
year = date.getFullYear(); | |
month = ('0' + (date.getMonth()+1)).slice(-2); | |
day = ('0' + date.getDate()).slice(-2); | |
return year + "-" + month + "-" + day; | |
} | |
function dateIterator (colBaseName, startDate, dayCount) { | |
var date = startDate | |
var i = 0; | |
var collectionNames = []; | |
while (i < dayCount) { | |
date.setDate(date.getDate()+1); | |
collectionNames.push(colBaseName + "_" + getDateString(date)); | |
i++; | |
} | |
return collectionNames; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment