怎么修改 mongodb 字段类型

2019-11-15

Mongodb 字段类型对映表

Type NameType Number
Double1
String2
Object3
Array4
Binary data5
Object id7
Boolean8
Date9
Null10
Regular expression11
JavaScript code13
Symbol14
JavaScript code with scope15
32-bit integer16
Timestamp17
64-bit integer18
Min key255
Max key127

把 published_at 字段 str 类型从改为 Date 类型

db.bitcoin.find( { 'published_at' : { $type : 2 } } ).forEach( function (x) {   
  x.published_at = new Date(x.published_at); // convert field to string
  db.bitcoin.save(x);
});

参考链接