How to update TTL property "expireAfterSeconds" in the _ts index after its already created?

subster 0 Reputation points
2023-10-30T18:57:01.19+00:00

I am trying to update the *expireAfterSeconds *property in my test cosmosDB collection after its been created. I first created this index by following the command listed here: https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/time-to-live

globaldb:PRIMARY> db.coll.createIndex({"_ts":1}, {expireAfterSeconds: 400000})

I tried running this command again with a new value but it does not work as the index already exists.

According to this MongoDB documentation https://www.mongodb.com/docs/v3.2/reference/command/collMod/#change-expiration-value-for-indexes, I should be using collMod command to update the field.

However when I run this command in the Mongo Shell:

db.runCommand({ collMod:"coll", index:{ keyPattern:{ "_ts":1}, expireAfterSeconds:3600} })

I get this error:

{
        "_t" : "OKMongoResponse",
        "ok" : 0,
        "code" : 115,
        "errmsg" : "Command is not supported.  ConnectionId 843ed8dc-89e8-4327-880d-69969744de90  ActivityId: 7f2b3a2d-0000-0000-0000-000000000000",
        "$err" : "Command is not supported.  ConnectionId 843ed8dc-89e8-4327-880d-69969744de90  ActivityId: 7f2b3a2d-0000-0000-0000-000000000000"
}


User's image

The server is currently on MongoDB 3.2. How do I correctly update the index with a new TTL value?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,911 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.