Cosmos Mongo API - Unique and compound indexes do not support nested paths.

Prakash Singh Chauhan 1 Reputation point

I have the following schema:

const addressSchema = new Schema<AddressSchema>(
    street: String,
    postalCode: String,
    city: String

const detailsSchema = new Schema<DetailsSchema>(
  address: AddressSchema

Trying to make a unique index based on name and address.postalCode as follows:

db.profiles.createIndex({ name: 1, "address.postalCode": 1 }, { unique: true });

but this throws the following error:

 "ok" : 0,
 "errmsg" : "Unique and compound indexes do not support nested paths.",
 "code" : 115,
 "codeName" : "CommandNotSupported"

Is this error expected or am I doing something wrong? What is the suggested solution for this?
I was thinking of combining two fields and create a new field that will act as the unique index. Just exploring more options.

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,526 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. GeethaThatipatri-MSFT 29,012 Reputation points Microsoft Employee

    Hi, @Prakash Singh Chauhan Welcome to the Microsoft Q&A forum, and thanks for reaching out.
    As we understand the ask here is you are facing an issue while creating a unique compound index please correct me if my understanding is wrong.
    Can you try with the use case mentioned in the document.
    db.coll.createIndex({"children.$**" : 1})