ITPub博客

首页 > IT职业 > IT职场 > mongodb数据之间的转换

mongodb数据之间的转换

IT职场 作者:KingSunSha 时间:2021-09-11 10:14:28 0 删除 编辑

1、int转换为string类型

db.collectionName.find().forEach(function(x) {
x.FieldName = x.FieldName.toString();
db.collectionName.save(x);
});

2、string转换为Date类型

db.collectionName.find().forEach(function(x) {
x.FieldName = new ISODate(x.FieldName );
db.collectionName.save(x);
});

 3、string转换为int类型

//string转为int类型
db.collections.find().forEach( function (x) {
  x.ise= NumberInt (x.ise);
  db.collections.save(x);
});

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1011/viewspace-2833234/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: mysql如何修改表
请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    78
  • 访问量
    496