I have my mongoose model:
LogSchema = new Schema({
level : String,
code: String,
message: String,
Timestamp : {
type : Date,
default: Date.now
}
})
I'm trying to delete all documents older than 30 days (Timestamp field) using this code:
var d = new Date();
var older_than = new Date(d.setDate(d.getDate() - 30));
Log.remove({ Timestamp : {$lte : older_than } }, function(err) {
if (!err) {
console.log("Clean complete")
} else {
console.log("Clean error")
}
});
I see on console: "Clean complete", but I still have all documents older than 30 days.
Something wrong in my code?