enorl76
enorl76

Reputation: 2655

With Mongo, using C#, is there a way to query indexes and find one thats a TTL index?

I have found the Indexes property on IMongoCollection but it doesn't return the options on the indexes, only the indexed fields:

var indexes = collection.Indexes.List().ToList();

list is all BsonDocuments:

[v=2, key={ "_id": 1 }, name=_id_]
[v=2, key={ "fieldA": 1 }, name=fieldA_1]
[v=2, key={ "fieldB": 1, "fieldC": -1 }, name=fieldB_1__fieldC_-1]

none of the BsonDocuments returned include the options for the index, like expireAfterSeconds (a TTL index) so I can examine and check that theres a TTL index on the collection.

A little background, we store basically a detailed log (the message, the processing of the message, and the resulting response messages) which grows large fast, and many times our support staff, to get the system back online, just droip the collection... because sometimes even with 30 days TTL, theres a LOT OF GBs in there. When they drop the collection, it gets spontaneously rebuilt when anything saves, so now its even worse, theres no TTL index on that collection.

So our strategy was, on restart of app, to ensure the TTL index on the diagnostics collection is created but we cant ever seem to actually know via c# code, that theres an index on the collection that has expireAfterSeconds set.

Upvotes: 1

Views: 24

Answers (0)

Related Questions