MongoDB: remove unique constraint

前端 未结 3 1407
滥情空心
滥情空心 2021-01-04 01:12

I\'m trying the \"Develop a RESTful API Using Node.js With Express and Mongoose\" example and I ran into a problem with the MongoDB Schema:

POST: 
{ title: \         


        
相关标签:
3条回答
  • 2021-01-04 01:52

    I hope this will helpfull

    db.collection.getIndexes()
    

    Returns an array that holds a list of documents that identify and describe the existing indexes on the collection. now find your index name from list and then removed that index as below

    db.users.dropIndex("your_index_name_here")
    
    0 讨论(0)
  • "How does mongodb handle "alters" to the schema?"

    MongoDB is schema-less

    The only thing there uniqueness is enforced is on the indexing level where you can define indexes on a collection with unique criteria. So you may want to remove the related index and re-created it if necessary.

    0 讨论(0)
  • 2021-01-04 02:06

    When you add a unique constrains on to mongoose schema than an index will be created on the same key. For eg: if you have a schema key called style then an index will be created as style_1. Even when you modify the schema the index which is already created will be still there. You need to delete this index in order to reset the unique constrains.

    If you have mongoDB Compass installed then you can go to collection->indexes and delete the same. The same interface is available on the Atlas Web interface as well. In my case I had an index on the key url, which I have deleted.

    0 讨论(0)
提交回复
热议问题