Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
830 B
1
Indexable
Never
const shopMap = await ShopMaps.Model.find({
				'alleys.racks': {
					$elemMatch: {
						$elemMatch: {
							_id: rack_id,
						},
					},
				},
				shop_id,
			});
			const rack = await Racks.Model.findOne({ _id: rack_id, shop_id }).select({ alley_id: 1 }).lean();

			if (shopMap && rack) {
				const { alley_id } = rack;

				await ShopMaps.Model.updateOne(
					{
						'alleys.id': alley_id,
						shop_id,
						'alleys.racks': {
							$elemMatch: {
								$elemMatch: {
									_id: rack_id,
								},
							},
						},
					},
					{
						$set: {
							'alleys.$[i].racks.$[j].$[k].is_deleted': true,
						},
					},
					{
						arrayFilters: [
							{
								'i.id': alley_id,
							},
							{
								'j._id': 0 || 1,
							},
							{
								'k._id': rack_id,
							},
						],
					});
			}
		}
	}