MongoDB 数据类型转换
2019-12-04 本文已影响0人
沧海2122537190
MongoDB版本在4.0以下可使用,下列方式
转换为int
db.collectionName.find().forEach(function(x) {
x.FieldName = parseInt(x.FieldName);
db.collectionName.save(x);
});
4.0以上版本 参考官方文档
int转string
db.collectionName.find().forEach(function(x) {
x.FieldName = x.FieldName.toString();
db.collectionName.save(x);
});
4.0以上版本 参考官方文档
string转Date
db.collectionName.find().forEach(function(x) {
x.FieldName = new ISODate(x.FieldName );
db.collectionName.save(x);
});
4.0以上版本 参考官方文档