Hi @Bruno_Cardoso,
I updated my answer. You should not compare createdAt
, but _id
property. Can you try it again with this query:
const mongoose = require('mongoose');
let remove = await mongoose.connection.db.collection("mycollection").deleteMany({
_id: {
$lt: mongoose.Types.ObjectId(
Math.floor(new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) / 1000).toString(16) + '0000000000000000'
),
}
});