【发布时间】:2014-04-11 23:28:08
【问题描述】:
产品和变体价格
在所有products.Variants.Price 中找到尺寸较小的最小值并将其更新 15%
{
"_id" : 23,
"name" : "Polo Shirt",
"Variants" : [
{
"size" : "Large",
"Price" : 82.42
},
{
"size" : "Medium",
"Price" : 20.82 // this should get increased by 15%
},
{
"size" : "Small",
"Price" : 42.29
}
]
},
{
"_id" : 24,
"name" : "Polo Shirt 2",
"Variants" : [
{
"size" : "Large",
"Price" : 182.42
},
{
"size" : "Medium",
"Price" : 120.82 // this should get increased by 15%
},
{
"size" : "Small",
"Price" : 142.29
}
]
}
我开始了这样的事情。不确定这是否是正确的开始
db.products.find().forEach(function(product){
var myArr = product.Variants;
print(myArr.min());
});
【问题讨论】:
-
如果您需要在 Variants 中查找 min,为什么还要遍历集合中的文档?
-
我需要更新最小的。
-
集合中所有文档的最小值还是文档中所有变体的最小值?
-
@SalvadorDali 集合中每个文档的最低变体价格
-
尺寸较小的集合中每个文档的最低变体价格
标签: node.js mongodb mongo-shell