Search code examples
mongodbindexingfieldazure-cosmosdb

Azure cosmos DB 3.6 Mongo doesn't support Compound index that has embedded field


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


Solution

  • 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.