码迷,mamicode.com
首页 > 数据库 > 详细

MongoDB类型转换

时间:2019-06-14 15:00:13      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:ble   mongodb   double   oda   function   person   mongo   span   date   

一.查询字段类型

db.person.find({address:{$type:2}}) //查询address字段数据类型为字符串
db.person.find({address:{$type:"string"}}) //查询address字段数据类型为字符串

二.类型转换

假设有表item_infoY(stae,time,date)

//string转为double类型
db.item_infoY.find().forEach( function (x) {
x.state = parseInt(x.state);
db.item_infoY.save(x);
});

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

//string转化为date类型
db.item_infoY.find().forEach( function (x) {
x.date = new ISODate(x.date);
db.item_infoY.save(x);
});

MongoDB类型转换

标签:ble   mongodb   double   oda   function   person   mongo   span   date   

原文地址:https://www.cnblogs.com/aspsea/p/11022768.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!