这是我的收藏:
{
"_id":"634861c7ee495492da321b2b",
"name": "new product int",
"price": 333,
"description": "sdsad",
"quantity": "1",
"category": "test",
"MRP": 333
},
{
"_id": "6357a1361e40021f6f71897a",
"name": "New Product 01",
"price": 458,
"description": "",
"quantity": "5",
"category": "test",
"MRP": 458
}
我尝试使用下面的update Many()语法对所有产品应用50%的折扣:
db.collection.updateMany({category:"test"},[{
$set: {
price: {
$floor: {
$subtract: [
"$price",
{
$multiply: [
{
$divide: [
"$price",
100
]
},
50
]
}
]
}
}
}
}
])
但是当我运行这个查询时,我的数据库中没有任何变化。有没有其他的方法来完成这个任务?
其中说:
acknowledged: true,
modifiedCount: 0,
upsertedId: null,
upsertedCount: 0,
matchedCount: 2
2条答案
按热度按时间q8l4jmvw1#
我试过了,它正在工作。只要用集合名称替换
collection
即可。dauxcl2d2#
可能是因为它是
collectio
而不是collection