mongodb - MongoDB - 如何通过字符串操作更新值
问题描述
我id
在数据库中有字段,值在模式中entity_id_aaaa-bbbb-cccc-dddd
。我需要用下划线更改模式,并将所有现有文档中的全部替换-
为_
下划线(最终结果应该是entity_id_aaaa_bbbb_cccc_dddd
),MongoDb 中是否有任何更新查询可以帮助我?
解决方案
db.collection.find({id:id}).forEach(function(document) {
document.id = document.id.replace('entity_id_aaaa-bbbb-cccc-dddd', 'entity_id_aaaa_bbbb_cccc_dddd');
db.collection.save(document);
});
推荐阅读
- kubernetes - 从 pod 访问入口 IP
- node.js - 从 Microsoft graph api 列出用户所需的权限
- kubernetes - Kubernetes 集群中的请求缓冲
- asp.net - 403 禁止访问在 IIS 上托管的 asp.net 网站上使用 ssl 的图像被拒绝
- python - 将直方图箱添加在一起并绘制图形
- maven - Maven 插件中与 Eclipse Sisu/Guice 的自定义绑定
- python - tkinter 中的 scroll_text.insert 在程序完成后运行
- python - QTreeView/QFileSystemModel - 比较文件和显示颜色
- javascript - 在css中将图像url作为背景导入时出现Webpack错误
- javascript - 如何在使用 .map() 呈现的按钮之间切换 CSS 类