[SERVER-12478] There seems to be no way to check if collection has TTL index Created: 25/Jan/14  Updated: 10/Dec/14  Resolved: 27/Jan/14

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.4.9
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Teemu Ikonen Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

Is there any way to check collection index is set with TTL like expireAfterSeconds?

The db.mycoll.stats() does not seem to tell that.

> db.alliancej.ensureIndex(

{created: 1}

,

{expireAfterSeconds: 300}

)
> db.alliancej.stats()
{
"ns" : "map_cat.alliancej",
"count" : 1,
"size" : 96,
"avgObjSize" : 96,
"storageSize" : 8192,
"numExtents" : 1,
"nindexes" : 3,
"lastExtentSize" : 8192,
"paddingFactor" : 1,
"systemFlags" : 0,
"userFlags" : 1,
"totalIndexSize" : 24528,
"indexSizes" :

{ "_id_" : 8176, "uid_1" : 8176, "created_1" : 8176 }

,
"ok" : 1
}



 Comments   
Comment by Teemu Ikonen [ 26/Jan/14 ]

Thanks, this is what I needed.

Comment by J Rassi [ 25/Jan/14 ]

You can use db.alliancej.getIndexes() to look at the index list for a collection, or check if the following evaluates to a positive value:

db.system.indexes.count({ns: "map_cat.alliancej", expireAfterSeconds: {$exists: true}})}}

Generated at Thu Feb 08 03:28:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.