mongodb - 用 mongodb 中的旧值更新子文档值?
问题描述
我想四舍五入保存在这个集合中的所有价格(有大量文档)我怎么能做到这一点而无需遍历所有文档并更新每个文档?
输入:
[{
"_id" : ObjectId("5e05453d88ce103684d3b7e5"),//id is primary key for the root document
"RoomTypes" : [
{
"Code" : "STDB",//(Code is ducument leve primary key for this subdocument)
"RatePlans" : [
{
"Code":"standard",//(Code is ducument leve primary key for this subdocument)
"Rates" : [
{
"_value" : {
"Occupancy" : NumberInt(1),
"Currency" : "IRR",//(Occupancy an Currency are ducument leve primary key for this subdocument)
"Amount" : 3560.5,
}
},
{
"_value" : {
"Occupancy" : NumberInt(1),
"Currency" : "EURO",//(Occupancy an Currency are ducument leve primary key for this subdocument)
"Amount" : 35.5,
}
}
]
}
]
}
]
},
{
"_id" : ObjectId("5e05453d88ce103684d3b7e5"),//id is primary key for the root document
"RoomTypes" : [
{
"Code" : "STDB",//(Code is ducument leve primary key for this subdocument)
"RatePlans" : [
{
"Code":"standard",//(Code is ducument leve primary key for this subdocument)
"Rates" : [
{
"_value" : {
"Occupancy" : NumberInt(1),
"Currency" : "IRR",//(Occupancy an Currency are ducument leve primary key for this subdocument)
"Amount" : 3560.2,
}
}
]
}
]
}
]
}]
预期结果:
[{
"_id" : ObjectId("5e05453d88ce103684d3b7e5"),//id is primary key for the root document
"RoomTypes" : [
{
"Code" : "STDB",//(Code is ducument leve primary key for this subdocument)
"RatePlans" : [
{
"Code":"standard",//(Code is ducument leve primary key for this subdocument)
"Rates" : [
{
"_value" : {
"Occupancy" : NumberInt(1),
"Currency" : "IRR",//(Occupancy an Currency are ducument leve primary key for this subdocument)
"Amount" : 3561,
}
},
{
"_value" : {
"Occupancy" : NumberInt(1),
"Currency" : "EURO",//(Occupancy an Currency are ducument leve primary key for this subdocument)
"Amount" : 36,
}
}
]
}
]
}
]
},
{
"_id" : ObjectId("5e05453d88ce103684d3b7e5"),//id is primary key for the root document
"RoomTypes" : [
{
"Code" : "STDB",//(Code is ducument leve primary key for this subdocument)
"RatePlans" : [
{
"Code":"standard",//(Code is ducument leve primary key for this subdocument)
"Rates" : [
{
"_value" : {
"Occupancy" : NumberInt(1),
"Currency" : "IRR",//(Occupancy an Currency are ducument leve primary key for this subdocument)
"Amount" : 3560,
}
}
]
}
]
}
]
}]
解决方案
推荐阅读
- php - 在 PHP 中使用正则表达式来验证名称
- c++ - 如何在 bash 中使用管道在 c++ 中使用 getenv() 访问文件?
- javascript - 我的网站在 heroku 上,我想在其中集成一个博客。我尝试过 Butter CMS,但它非常昂贵。我应该如何处理这个?
- php - PHP 可以处理 $_POST 与另一个字段形式相同的多维数组作为键吗?
- powershell - 访问权和所有权 Powershell
- c++ - 在 C++ 中复制赋值构造函数
- javascript - 当我完成拖动并且鼠标上升时,如何使我的可拖动 div 不运行 onClick 函数?
- python - 在 python 中使用 stackdriver 记录器的资源类型?
- r - 使用显示不同图的两个不同数据集创建单个闪亮的应用程序
- javascript - 如何修改rows().data()获取每一行的值的方式?