进入mongodb bin的工作目录下 ./mongodb执行下面命令
Long转换为String
use userc_db;
db.t_user_favorite_item.find({userId:{$type:18}}).forEach(function(x){x.userId=""+x.userId;db.t_user_favorite_item.save(x)});
String转为Long
db.jobtracker_data.find({'collect_time' : { $type : 2 }}).forEach(function(x) {
x.collect_time = parseInt(x.collect_time);
db.jobtracker_data.save(x);
})
下面给出mongodb基于bson类型的列表:
Long转换为String
use userc_db;
db.t_user_favorite_item.find({userId:{$type:18}}).forEach(function(x){x.userId=""+x.userId;db.t_user_favorite_item.save(x)});
String转为Long
db.jobtracker_data.find({'collect_time' : { $type : 2 }}).forEach(function(x) {
x.collect_time = parseInt(x.collect_time);
db.jobtracker_data.save(x);
})
下面给出mongodb基于bson类型的列表:
Type Description | Type value |
---|---|
Double | 1 |
String | 2 |
Object | 3 |
Array | 4 |
Binary data | 5 |
Object id | 7 |
Boolean | 8 |
Date | 9 |
Null | 10 |
Regular expression | 11 |
JavaScript code | 13 |
Symbol | 14 |
JavaScript code with scope | 15 |
32-bit integer | 16 |
Timestamp | 17 |
64-bit integer | 18 |
Min key | 255 |
Max key | 127 |