mongoDB/mongoose: unique if not null
Yes, it is possible to have multiple documents with a field set to null or not defined, while enforcing unique "actual" values. requirements: MongoDB v3.2+. Knowing your concrete value type(s) in advance (e.g, always a string or object when not null). If you're not interested in the details, feel free to skip to the implementation section.
https://stackoverflow.com/questions/7955040/mongodb-mongoose-unique-if-not-null