一.查询字段类型
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);
});
//date转化为string类型
db.item_infoY3.find().forEach( function (x) {
x.date = x.date.toISOString();
db.item_infoY3.save(x);
});