SyntaxFix
Write A Post
Hire A Developer
Questions
For anybody falling on this old solution. There is a better way from the mongoose docs.
var s = new Schema({ name: { type: String, unique: true }}); s.path('name').index({ unique: true });