TTL Index does not work on my collection

1,696 views
Skip to first unread message

uma

unread,
Oct 17, 2013, 10:18:00 AM10/17/13
to mongod...@googlegroups.com
Hi,

I've created a TTL Index on my collection "log4netlogs" and set to expire after 30 days (30*24*60*60)

> db.log4netlogs.ensureIndex({Timestamp: 1}, {expireAfterSeconds: 2592000})
> db.log4netlogs.getIndexes()
[
        {
                "v" : 1,
                "key" : {
                        "_id" : 1
                },
                "ns" : "AIS.log4netlogs",
                "name" : "_id_"
        },
        {
                "v" : 1,
                "key" : {
                        "Timestamp" : 1
                },
                "ns" : "AIS.log4netlogs",
                "name" : "Timestamp_1",
                "expireAfterSeconds" : 2592000
        }
]


And I ran the below command after 5-10 mins. 
It doesn't seem to have expired the below document . Today's date is Oct 17th 2013 and ideally anything at least before Sept 17th 2013 should have been expired.
Can anyone please take a look at and let me know what is it that I am doing wrong.



> db.log4netlogs.find({_id:ObjectId("523267d59047311260a300ed")}).pretty()
{
        "_id" : ObjectId("523267d59047311260a300ed"),
        "Timestamp" : ISODate("2013-09-13T01:18:13.500Z"),
        "Level" : "INFO",
        "Logger" : "Test",
        "Message" : "Stop Scheduler called",
        "ApplicationName" : "SchedulerService",
        "ComputerName" : "TEST01"
}

Thanks.
Uma


Asya Kamsky

unread,
Oct 18, 2013, 4:15:19 AM10/18/13
to mongodb-user
Is this a stand-alone mongod or part of a replica set?

It looks like the index is correct - I tried exact record and syntax
that you did and TTL thread deleted the document within 60 seconds.
It is possible that your TTL monitor thread isn't running - there are
several circumstances when that can happen. If this node used to be
part of a replSet and still has the set config, TTL won't run. If
this is older than 2.2 version then TTL didn't exist. There may be
other situations. It could also be that the time on the server is way
off...

Asya
> --
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
>
> ---
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mongodb-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

uma

unread,
Oct 18, 2013, 11:37:32 AM10/18/13
to mongod...@googlegroups.com
Asya,

Thanks for replying. I think I figured what the problem is. 
My collection is a capped collection and I don't think TTL is compatible with it.

Thanks.
Uma

Daniel Coupal

unread,
Oct 18, 2013, 12:39:32 PM10/18/13
to mongod...@googlegroups.com
Uma,

you are right, "TTL" is not compatible with capped collections.

  => TTL Collections are not compatible with capped collections.

You may want to open an enhancement request, so TTL indexes can not be created on capped collections. The 'ensureIndex' command should return an error and not create the index.

Regards,

Daniel Coupal

uma

unread,
Oct 21, 2013, 1:28:55 PM10/21/13
to mongod...@googlegroups.com
Thanks Daniel.
Will do that.
Reply all
Reply to author
Forward
0 new messages