I am attempting to delete all the documents returned by an aggregation in Mongodb.
The query I have is as follows:
db.getCollection("Collection")
.aggregate([
{
$match: { status: { $in: ["inserted", "done", "duplicated", "error"] } }
},
{
$project: {
yearMonthDay: { $dateToString: { format: "%Y-%m-%d", date: "$date" } }
}
},
{ $match: { yearMonthDay: { $eq: "2019-08-06" } } }
])
.forEach(function(doc) {
db.getCollection("Collection").remove({});
});
I tried this query but it removes all the data in the database, any suggestions please?