Skip to content

Instantly share code, notes, and snippets.

@johntron
Created May 29, 2013 16:04
Show Gist options
  • Save johntron/5671463 to your computer and use it in GitHub Desktop.
Save johntron/5671463 to your computer and use it in GitHub Desktop.
For a collection of subdocuments, adds a human-friendly date string using an existing timestamp
var coll = '101.google.youtube';
var r = db[coll].find({"$where": "typeof this.statistics_log != 'undefined' && this.statistics_log.length > 0"});
while (r.hasNext()) {
var d = r.next();
for(var i = 0, j = d.statistics_log.length; i < j; i++) {
var execute_at = new Date(d.statistics_log[i].execute_at_ts * 1000);
d.statistics_log[i].execute_at = execute_at.toString();
}
print(db[coll].update({"_id": d._id}, d));
}
// Run from command line with: mongo warehouse add_date_strings.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment