2014년 12월 11일 목요일

TTL not working

I have this TTL index set on Mongo

 {
                "v" : 1,
                "key" : {
                        "tokentime" : 1
                },
                "ns" : "dbname.tablename",
                "name" : "tokentime_1",
                "expireAfterSeconds" : 180
        }

I use this java code to insert data into tokentime column

DBCollection tableTemp = db.getCollection("tablename");
BasicDBObject time = new BasicDBObject("tokentime", new java.util.Date());
BasicDBObject connectionHistory = new BasicDBObject();

connectionHistory.put("tokentime", time);
tableTemp.save(connectionHistory);


But my document does not get deleted after 180 seconds. Could you tell me what is wrong?



The background TTL task that removes expired documents runs every 60 seconds and may also take some time to run depending on your workload: http://docs.mongodb.org/manual/core/index-ttl/.

You should not expect documents to be immediately removed on reaching their expiry, but in the best case they should be removed soon after.

Do documents get removed eventually if you wait an extra minute or two? It looks like you're setting a valid date in your Java code, but field type is another common error to check. Any documents with a non-date value set in the TTL field will not match the TTL expiry query.


댓글 없음:

댓글 쓰기