0
votes

I have created a new collection in CosmosDB and I'm trying to create my first index.

I run the following script:

db.getCollection("mycoll").createIndex({ "UniqueId": 1 }, { "name": "udx_mycoll_UniqueId", "unique": true });

And it produces the response:

{
    "_t" : "CreateIndexesResponse",
    "ok" : 1,
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 3,
    "numIndexesAfter" : 4
}

Which looks promising, but when I run the query:

db.mycoll.getIndexes();

No indexes are found. I tried running it in Compass too, and I get an error when I switch to the indexes tab:

'$indexState' is not supported

Anyone able to shed some light on this?

1
Checking with the team on this.Chris Anderson-MSFT
Not sure if it's a typo, but you createIndex on "mycoll", then getIndexes on "woods" which doesn't seem right.Chris Anderson-MSFT
@ChrisAnderson-MSFT sorry - that was a typo - the collection name was the same in both when I ran it. I have edited it above.booler

1 Answers

0
votes

It works if you use Robo3T client.
However, the custom name is not taken into account.

In your case:

db.getCollection("mycoll").createIndex({ "UniqueId": 1 }, { "name": "udx_mycoll_UniqueId", "unique": true });

you will end up with an index named: UniqueId_1