Reputation: 7932
I created a unique index using Mongoose sometime ago in my database.
Model.index({name: 1, location: 1}, {unique: true});
Now due to some coding changes, I would like to drop the uniqueness on the index. Is there a way to just drop the uniqueness on the index?
The only thing I can come up with is to just do
Model.dropIndex({name: 1, location: 1});
Model.index({name: 1, location: 1});
Is this correct? Or is there less a confusing way to write the code..
Upvotes: 4
Views: 4466
Reputation: 711
If you use a UI tool like RoboMongo, you can drop it from its UI
Upvotes: 0
Reputation: 2636
Yes that is correct way of dropping. You can either do it from mongo client.
or from node server like this
Model( { {name: 1, location: 1} }, function(err){
if(err){
res.send("error");
}
else{
res.send("success");
}
});
Upvotes: 0