3

When I run the following command in Cosmos DB 3.6,

db.collectionName.ensureIndex({"Contract.ContractNumber":1, "PBPNumber":1})

Contract.ContractNumber is the sub-document path.

I got his error

{
   "ok" : 0,
   "errmsg" : "Compound index does not currently support nested documents or arrays.",
   "code" : 115,
   "codeName" : "CommandNotSupported"
}

The same command succeeds in out of box Mongo.

Is there anyway to do it?

Thanks

3 Answers 3

2

Based on the CommandNotSupported error message,the feature is not supported exactly currently.

Per my knowledge, CosmosDB just supports a subset of the MongoDB API. CosmosDB has some different behaviours and results. But the onus is on CosmosDB to improve their emulation of MongoDB.

Surely, you could add feedback here to submit your requirements.Or you could consider using MongoDB Atlas on Azure if you'd like full MongoDB feature support.

Sign up to request clarification or add additional context in comments.

2 Comments

I've created a new request, as I came across the same issue: feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/…
@PeterY, please find this link to the current CosmosDB Mongo API indexing options. I hope you found a solution to your issue. learn.microsoft.com/en-us/azure/cosmos-db/mongodb-indexing
1

Regarding @leopold.talirz answer:

It seems that it actually is possible to enable this feature all by yourself. Please see this document for overall reference, and then there's a link to another one which explains step-by-step how to do it.

EDIT: most recent news seem to be here:

https://github.com/MicrosoftDocs/azure-docs/issues/101394#issuecomment-1318041341

https://github.com/hashicorp/terraform-provider-azurerm/issues/19192#issuecomment-1341332461

It seems it WILL be available to users "shortly", but so far, it's only available to MSFT, and the docs were updated too soon.

what a mess

Comments

1

As of May 2022, indexing is available for nested compound indices, as long as none of the properties in the dot-notation path (excluding the last element) is an array.

However, as explained here.

Because of the difficulty of ensuring that all data within a collection cannot include an array on the property being set, we can only enable this via support ticket

P.S. We found that Azure support was able to enable the feature on an entire CosmosDB instance, not just on individual collections.

1 Comment

It seems that there's another requirement: no 'unique' flag on any of the indexed fields.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.