'MongoDB - How can I define a field as unique and nullable in MongoDB?

i am writing in typescript,

i am trying this in member model:

mail: {
    type: String,
    unique: true,
    nullable: true,
    default: null,
      }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source