在实际应用中,我们有时候会遇到“MongoDB中常见的数据怎么转换,方法是什么”这样的问题,我们该怎样来处理呢?下文给大家介绍了解决方法,希望这篇“MongoDB中常见的数据怎么转换,方法是什么”文章能帮助大家解决问题。
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);
});
现在大家对于MongoDB中常见的数据怎么转换,方法是什么的内容应该都有一定的认识了吧,希望这篇能对大家有所帮助。