最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
mongo修改字段类型(string to int)的教程
时间:2022-06-29 10:33:36 编辑:袖梨 来源:一聚教程网
mongo可以通过find(...).forEach(function(x) {})语法来修改collection的field类型。
假设collection为foo,field为bad:
转换为int类型:
db.foo.find({bad: {$exists: true}}).forEach(function(obj) {
obj.user_id = new NumberInt(obj.user_id);
db.foo.save(obj);
});
同理转换为string类型:
db.foo.find( { bad : { $exist : true } } ).forEach( function (x) {
x.bad = new String(x.bad); // convert field to string
db.foo.save(x);
});
相关文章
- 为ABP框架添加基础集成服务 09-17
- Deep Agents、LangChain 与 LangGraph:三层 Agent 技术栈对比 09-17
- MCP 客户端实战:快速注册 GitHub 工具 09-17
- 搭建基础结构的ABP解决方案介绍 09-17
- 借助 GPT6 与 Hyper3D MCP 打造可探索的 3D 个人网站 09-17
- AI Agent 开发进阶第八课:角色模式与流式输出 09-17