I have an email field, where I want unique emails. I also want to have the possiblity of an empty field. I don't want it to check uniqueness if the email is empty/null/not present.
Here is my List schema defined in Keystone:
Book.add({
number: { type: Types.Number },
email: { type: Types.Email, initial: true, index: true, unique: true },
token: { type: Types.Text },
title: { type: Types.Text, initial: true },
author: { type: Types.Text, initial: true },
name: { type: Types.Text, initial: true },
dedication: { type: Types.Textarea, initial: true },
image: { type: Types.CloudinaryImage }
});
Keystone exposes the mongoose schema, so I can access that. I could add a custom validation which makes a query except if field empty, but I'm hoping for something more elegant.
I already have plenty of data, I don't know if that makes the indexing stuff more complex.