I have the following schema:
const addressSchema = new Schema<AddressSchema>(
{
street: String,
postalCode: String,
city: String
},
const detailsSchema = new Schema<DetailsSchema>(
name:string:
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.