Azure CosmosDB API for MongoDB TTL index failed to create

Priyanka P 21 Reputation points
2022-01-18T13:02:26.79+00:00

Hi,

I have created an index on a collection in Azure Cosmos DB API for MongoDB 3.6 version using Shell available with in the azure cosmos as below:

db.coll.createIndex( { "_ts": 1 }, { expireAfterSeconds: 3600 } )

ERROR: createIndex is not implemented on this tool, please use your favorite Mongo framework or third party tools.

Please help what is the correct syntax to create ttl index in Azure Cosmos DB API for MongoDB.

And also it is observed that _ts field is not available in the documents of MongoDB API whereas in SQL API it is available.

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

1 answer

Sort by: Most helpful
  1. GeethaThatipatri-MSFT 29,542 Reputation points Microsoft Employee Moderator
    2022-01-19T23:48:54.27+00:00

    Hi, @Priyanka P the above-mentioned screenshot is from the portal the recommended one is native mongo shell or mongo3t tool, not the portal. can you please give it a try using the recommended one.
    globaldb:PRIMARY> db.testttl01.createIndex({"_ts":1}, {expireAfterSeconds: 10})
    {
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 2,
    "numIndexesAfter" : 3,
    "ok" : 1
    }
    globaldb:PRIMARY>
    Regards
    Geetha


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.