Hi @Bruno_Cardoso,
I see you have your custom date format. In that case you can use _id
property which is of type ObjectId. It has createdAt
built in. You can try this query:
let remove = await mongoose.connection.db.collection("mycollection").deleteMany({
_id: {
$lt: ObjectId(
Math.floor(new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) / 1000).toString(16) + '0000000000000000'
),
}
});