惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
量子位
博客园 - 司徒正美
V
V2EX
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
N
Netflix TechBlog - Medium
L
LangChain Blog
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
A
About on SuperTechFans
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - shareach

博客搬家了,欢迎访问 http://blog.csdn.net/yinpengxiang/ IOS Storyboard使用-模拟登录、注册、混合使用 XCode 细点 蛋痛的C#和.net,采集问题(小数点) Mapbar POI 转 经纬度坐标的各个版本 Android 自动化功能测试神器ChimpChat(MonkeyRunner) .Net C# 的一个bug(暂时命名为Bug) MongoDB的GeoSpatial索引 之 GeoNear命令,取得距离 MongoDB的GeoSpatial索引 Android + HTML开发手机应用 demo 代码 commonsware-Android平台可复用代码仓库 jqMobi + Android 试手 服务端通过设置 响应头允许其他域名跨域访问数据 Android上 用Html5做界面,javascript调用摄像头实例 Android 拍照加剪切处理方式 css3替代图片的尖角圆角效果 抛弃作为mongoDB做主存储的一些关键因素 ibatis3.06 + spring 3.06+velocity 整合的VSSI框架测试 基于即时更新的缓存策略设计草稿
MongoDB的主键类型修改,记录下
shareach · 2013-01-01 · via 博客园 - shareach

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

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

x._id=""+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