Reputation: 2261
I am trying to do the following date conversion on multiple collections:
db.u201409.find().snapshot().forEach(
function (e) {
e.sta = new Date(e.start);
e.sto = new Date(e.stop);
db.u201409.save(e);
}
)
As it can be seen, this is only for one collection, namely "u201409". The format is uYYYYMM
. I need to execute this exact same command for the collections from 201409 up until 201604, so for u201409, u201410, u201411, u201412, u201501, ..., u201604.
Is this possible using a shell script, and if so, how can this be accomplished?
Upvotes: 0
Views: 366
Reputation: 1334
The Mongo Shell command language is JavaScript, so just write JavaScript:
var a = ["u201401", "u201402"...]
for (var i = 0; i < a.length; i++) {
db[a[i]].find().snapshot().forEach(
...
)
}
Upvotes: 2