Skip to content

Instantly share code, notes, and snippets.

@droustchev
Last active August 29, 2015 13:56
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 droustchev/8921021 to your computer and use it in GitHub Desktop.
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.
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