Hey guys!
Is it possible to create a query that deletes all of the expired deals from the deals collection except from the latest 5 from each store?
This examples has 24 deals split between 2 stores. Basically it should only care about the deals that has any value in the dateTo field and make sure it’s expired (the date have passed already. And then also i want to keep the latest 5 expired deals from each store. Delete the rest.
[
{dateTo: "2023-01-09", store: ObjectId("100000000000000000000000")},
{dateTo: "2023-01-10", store: ObjectId("100000000000000000000000")},
{dateTo: null, store: ObjectId("100000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("100000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("100000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("100000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("100000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("100000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("100000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("100000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("100000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("100000000000000000000000")},
{dateTo: "2023-01-09", store: ObjectId("200000000000000000000000")},
{dateTo: "2023-01-10", store: ObjectId("200000000000000000000000")},
{dateTo: null, store: ObjectId("200000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("200000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("200000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("200000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("200000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("200000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("200000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("200000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("200000000000000000000000")},
{dateTo: "2023-01-07", store: ObjectId("200000000000000000000000")}
]
So this example it should delete 4x deals from each of the 2 stores.