I have a unique Array property in my document that is filled with lovely fluffy objects. Now, I am looking to remove all objects within a specific range -> qdate:20210225.
The property in the database is named weeks and appears as follows:
[
{
"time": [
"06",
"00"
],
"active": false,
"reason": "",
"bookTime": "202102250600",
"qdate": 20210225,
"booked": false
},
...
I attempted to delete one of these fluffy objects, but others remain unaffected. I tried different combinations like this:
const company = await Company.updateMany(
{ email: 'example@email.com' },
{ $pullAll: [{ 'weeks.qdate': 20210225 }] },
(err, data) => {
if (err) console.log(err);
}
);
const company = await Company.updateMany(
{ email: 'another@example.com' },
{ $pullAll: [{ 'weeks': { $elemMatch: { qdate: 20210225 } } }] },
(err, data) => {
if (err) console.log(err);
}
);
I understand that from a query I can only pull one occurrence, so I could find just one object matching the value of qdate:20210225. I attempted an aggregate pipeline to get all occurrences, but I could only replace values, not delete entire objects.
Can someone please help me out?