у меня есть следующий документ, и я должен обновить promotion
объект в соответствии с promotionId
, выполняя, я могу обновить, но этот запрос стирает другие продукты, которые не имеют повышения в условии:
, если я использую обновление много я получаю Error: the update operation document must contain atomic operators
. Пожалуйста, помогите мне получить ошибку для обновления, но сохраняю продукты, в которых нет промо, которое я обновляю. / * 1 * /
db.fulFillmentCenter.update({},[
{
$addFields: {
exclusiveProducts: {
$filter: {
input: "$exclusiveProducts",
as: "product",
cond: {
$eq: [
"$$product.promotion.promotionId",
'promo1'
]
}
}
}
}
},
{$set: { "exclusiveProducts.promotion.description": "multi 2"}}
/ * 2 * /
{
"_id" : 1,
"_class" : "com.walmart.labsmx.exclusiveproducts.model.FulFillmentCenter",
"minDateDelivery" : 9,
"maxDateDelivery" : 2,
"deliveryCost" : 10.0,
"origin" : "string",
"active" : true,
"exclusiveProducts" : [
{
"_id" : NumberLong(1585867035599),
"upc" : "p1",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "debe aparece",
"startDate" : ISODate("2020-02-10T02:47:03.472Z"),
"endDate" : ISODate("2020-04-10T02:47:03.472Z"),
"active" : true,
"promotion" : {
"_id" : NumberLong(1585867035613),
"promotionId" : "promo1",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
},
{
"_id" : NumberLong(1585867035642),
"upc" : "p2",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "no debe aparece",
"startDate" : ISODate("2020-02-10T02:47:03.472Z"),
"endDate" : ISODate("2020-04-10T02:47:03.472Z"),
"active" : false,
"promotion" : {
"_id" : NumberLong(1585867035654),
"promotionId" : "promo1",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
},
{
"_id" : NumberLong(1585867035607),
"upc" : "p3",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "no debe aparece",
"startDate" : ISODate("2020-02-10T02:47:03.472Z"),
"endDate" : ISODate("2020-03-10T02:47:03.472Z"),
"active" : true,
"promotion" : {
"_id" : NumberLong(1585867035668),
"promotionId" : "promo1",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
},
{
"_id" : NumberLong(1585867035644),
"upc" : "p4",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "debe aparece",
"startDate" : ISODate("2020-02-10T02:47:03.472Z"),
"endDate" : ISODate("2020-05-10T02:47:03.472Z"),
"active" : true,
"promotion" : {
"_id" : NumberLong(1585867035632),
"promotionId" : "promo1",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
},
{
"_id" : NumberLong(1585867035666),
"upc" : "p5",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "no debe aparece",
"startDate" : ISODate("2020-05-10T02:47:03.472Z"),
"endDate" : ISODate("2020-07-10T02:47:03.472Z"),
"active" : true,
"promotion" : {
"_id" : NumberLong(1585867035591),
"promotionId" : "promo1",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
},
{
"_id" : NumberLong(1585867035669),
"upc" : "p20",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "no debe aparece",
"startDate" : ISODate("2020-05-10T02:47:03.472Z"),
"endDate" : ISODate("2020-07-10T02:47:03.472Z"),
"active" : true,
"promotion" : {
"_id" : NumberLong(1585867035661),
"promotionId" : "promo2",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
},
{
"_id" : NumberLong(1585867035643),
"upc" : "p21",
"totalStock" : 10,
"availableStock" : 10,
"price" : 0.0,
"origin" : "no debe aparece",
"startDate" : ISODate("2020-05-10T02:47:03.472Z"),
"endDate" : ISODate("2020-07-10T02:47:03.472Z"),
"active" : true,
"promotion" : {
"_id" : NumberLong(1585867035612),
"promotionId" : "promo3",
"description" : "string",
"startDate" : ISODate("2020-04-30T17:49:27.205Z"),
"endDate" : ISODate("2020-04-30T17:49:27.205Z"),
"active" : true
}
}
],
"exclusiveStores" : [
{
"storeId" : 123,
"origin" : "string"
}
]
}