json - 更新 Mongo 集合中同名的字段
问题描述
我的问题是,我有一个这样的集合:
"cost_price" : 79.9,
"list_price" : 189.9,
"sale_price" : 189.9,
"integrations" : {
"erp" : {
"mbm" : {
"cost_price" : 79.9,
"list_price" : 189.9,
"sale_price" : 189.9
},
"linx" : {
"cost_price" : 79.9,
"list_price" : 189.9,
"sale_price" : 200.1
}
},
"marketplace" : {
"netshoes" : {
"list_price" : 189.9,
"sale_price" : 199.9
}
},
"ecommerce" : {
"vtex" : {
"list_price" : 189.9,
"sale_price" : 189.9
},
"magento" : {
"list_price" : 189.9,
"sale_price" : 189.9
}
}
}
如何在单个查询中更新此集合中名为“list_price”的所有字段?
解决方案
可能对你有帮助。
db.products.updateMany({}, {
$rename: {
"list_price": "new_name",
"integrations.erp.mbm.list_price": "new_name",
"integrations.erp.linx.list_price": "new_name",
"integrations.erp.linx.list_price": "new_name",
"integrations.marketplace.netshoes.list_price": "new_name",
"integrations.ecommerce.vtex.list_price": "new_name",
"integrations.ecommerce.magento.list_price": "new_name"
}})
推荐阅读
- gcc - REGSITER_TM_CLONES 中的 Shift 操作的目的是什么?
- typescript - 安装 @google-cloud/storage 后如何解决 Firebase 函数中的 Typescript 类型错误
- javascript - 为什么打字稿假设总是有一个全局导出对象?
- performance - 将 20k 产品加载到 Opencart Journal Theme(版本 3.x)后,网站速度非常慢
- java - 简单计算器:加法错误输出
- c# - 控制台与 WebAPI 中共享类库的 MediatR 设置
- git - 如何向 .gitignore 添加内容?
- android - Flutter Launcher 图标没有改变?
- javascript - 它没有在控制台屏幕上显示任何输出。可能是什么问题
- python - Django DateTimeField 说“你比服务器时间提前 5.5 小时。”