I’m working with Mongodb and Nest Js.I have 2 schema X and Y. In X there is a property
export class X{
@Prop({required:true,unique:true})
email:string
}
which stops duplicates for the same email when try to create a document of X.
And In schema Y, X is embedded in Y schema. I have this in Y schema
export class Y{
@Prop({})
name : string;
@Prop({required:true})
x : X
}
Now When I create first Y document with X it creates, but when I try to create an other Y with different name , but with same X document, the property email in the X schema throws E11000 duplicate error.
I’m just embedding the X, i’m not creating a new X document, Why it is throwing error when I try to create Y document, why the email unique, is effecting Y schema, while I’m just simply embedding it.
I know by referencing X in Y solves the problem. But I want to embed X.
Is there a way to stop mongo to create unique index in the Y collection of the X property?