我拥有一个包含历史数据的MongoDB收集器,有id和时间。
I want to delete data from the collection older than a specific timestamp. But for every id at least one document (the newest) must stay in the collection.
附录一
{"id" : "11", "timestamp" : ISODate("2011-09-09T10:27:34.785Z")} //1
{"id" : "11", "timestamp" : ISODate("2011-09-08T10:27:34.785Z")} //2
{"id" : "22", "timestamp" : ISODate("2011-09-05T10:27:34.785Z")} //3
{"id" : "22", "timestamp" : ISODate("2011-09-01T10:27:34.785Z")} //4
... and I want to delete documents having a timestamp older than 2011-09-07 then 1 and 2 should not be deleted because they are newer. 4 should be deleted because it is older, but 3 should not be deleted (although it is older) because at least one document per id should stay in the collection.
Does anyone know how I can do this with casbah and/or on the mongo console?
Regards, Christian