I'm trying to insert a record in mongo that expires in sometime.
getMessagesCollection().ensureIndex(new BasicDBObject("createdAt", 1), new BasicDBObject("expireAfterSeconds", 10));
I insert my data like this
Map map = new HashMap();
map.put("_id", mongoMessage.getObjectId());
// Other code
map.put("createdAt", new Date());
getMessagesCollection().insert(convertToDBObject(map))
the field createdAt is a date and before inserting the object looks like this
{ "_id" : "551bf9b72bea951ecf53fc5f" , "createdAt" : { "$date" : "2015-04-01T09:59:19.723Z"} , ...}
But the record is not getting deleted. Can someone tell me what I'm doing wrong?