Drop index automatically for fields with unique attribute set to false
See original GitHub issueSo I was creating a user model and set the email field to unique:true
and everything seems to be fine, but when I decided that “Meh, I want the email to be NOT unique”, so remove the the unique:true
option, and guess what? … Yes you guessed it return duplicate error, so I added the unique:false
and set it to false
and the error still persisted. With a little research on stackoverflow I came across with this answer. Well the answer solved the problem but It’s such a bummer to drop the index manually. Wouldn’t it be nice if mongoose just drops the index automatically when the option is set to unique:false
? #midnightthoughts lol
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:6
Top Results From Across the Web
Difference between Unique Indexes and Unique Constraints ...
The only difference is that you cannot directly drop the unique Index created by the unique constraint in SQL Server.
Read more >Create and use an index to improve performance
If you create a unique index, Access doesn't allow you to enter a new value in the field if that value already exists...
Read more >How to remove unique key from mysql table - Stack Overflow
All keys are named, you should use something like this - ALTER TABLE tbl_quiz_attempt_master DROP INDEX index_name;. To drop primary key use this...
Read more >Working with Indexes | Manual | ArangoDB Documentation
By default, all user-defined indexes are non-unique. Only the attributes in fields are checked for uniqueness.
Read more >Unique Indexes — MongoDB Manual
MongoDB cannot create a unique index on the specified index field(s) if the collection already contains data that would violate the unique constraint...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
+1
Good suggestion, will keep it open for a future release, but not a high priority because index management is not really mongoose’s strong suit