由于前期设计不周,导致主键 _id是ObjectId, 不方便更新维护,后期修改太过麻烦,特此记录一笔

//这样将新建一条重复记录,我city 和 category是collection的中的唯一索引
db.CategoryCount.find({ "_id" : { "$type" : 7 } }).forEach(function(x){

x._+x.city+x.category;
db.CategoryCount.save(x);
});

//通过上面的调用,已经将记录复制了一份,主键未字符串类型,下面将删除老的ObjectId为主键的记录
db.CategoryCount.remove({ "_id" : { "$type" : 7 } });

//type对应的类型值为

类型
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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
猜你喜欢
  • 2021-08-26
  • 2021-11-28
  • 2021-11-28
  • 2021-07-27
  • 2022-02-12
  • 2021-08-20
  • 2022-01-30
相关资源
相似解决方案