Nitin Garg's answer above almost works, except his example converts from a string to a hash, NOT a string to an array.
Taking into account Joel Harris's comments, the proper solution would look like:
db.jobs.find( { "jobLocationCity" : { $type : 2 } } ).snapshot().forEach( function (x) {
x.jobLocationCity = [ jobLocationCity ];
db.jobs.save(x);
});
Or if using db.eval:
function f() {
db.jobs.find( { "jobLocationCity" : { $type : 2 } } ).snapshot().forEach( function (x) {
x.jobLocationCity = [ jobLocationCity ];
db.jobs.save(x);
});
}
db.eval(f);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…