The date type of StartTime is string so comparing with a date object in this case wont work.
Fortunately the string is an ISODate so the lexicographical order is equal to the chronological order.
So taking the ISOString from the date object will work: db.KerberosTgs_20230608031830.deleteMany( { StartTime : {"$lt" : (new Date(2023, 11, 1)).toISOString() }
Or use a string directly: db.KerberosTgs_20230608031830.deleteMany( { StartTime : {"$lt" : "2023-11-01T00:00:00.000Z" }})
The first one? could be syntax. Try assigning the value to variable first, and make sure the string is correct.
var deleteBefore = new Date(2023,11,1)
var dateString = deleteBefore.toISOString()
// inspect var
db.KerberosTgs_20230608031830.deleteMany( { StartTime : {"$lt" : dateString}})
Deleting documents will not free space back to the OS. The space created by document removal will be reused by the collection for future inserts and updates.
A collection can be compacted to reclaim the freed blocks. An alternative is to resync replicaset members this has the side effect of ‘defragmenting’ all collections.