mongoose add compound index code example Example: mongoose sparse index var User = new Schema({ name: { type: String, sparse: true } })