question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Drop index automatically for fields with unique attribute set to false

See original GitHub issue

So 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

2reactions
0xMarkiancommented, Jul 29, 2016

+1

2reactions
vkarpov15commented, Jun 25, 2016

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found