Вы можете добавить ограничение с атрибутом unique
. Это также добавит «уникальный» индекс для поля в вашу коллекцию:
var userSchema = mongoose.Schema({
username: { type: String, unique: true },
email: String,
password: String,
_todo: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Todo'}]
});