使用mongo shell转换字符类型

时间:2022-03-18 13:31:15

MongoDB数据类型如下:

类型 对应数字 别名 说明
Double1 1 double  
String 2 string  
Object 3 object  
Array 4 array  
Binary data 5 binData  
Undefined 6 undefined 弃用
ObjectId 7 objectId  
Boolean 8 “bool”  
Date 9 “date”  
Null 10 “null”  
Regular Expression 11 “regex”  
DBPointer 12 “dbPointer”  
JavaScript 13 “javascript”  
Symbol 14 “symbol”  
JavaScript(with scope) 15 “javascriptWithScope”  
32-bit integer 16 “int”  
Timestamp 17 “timestamp”  
64-bit integer 18 “long”  
Min key -1 “minKey”  
Max key 127 “maxKey”  

js修改语句:

db.getCollection('log_pages_day').find(
{'uv' : { $type : 18 }}
).forEach(
function(x) {
x.uv =NumberInt(x.uv);
db.log_pages_day.save(x);
})