MongoDB E11000 duplicate key error

前端 未结 2 2253
不思量自难忘°
不思量自难忘° 2021-02-20 16:59

I have a model that keeps erroring out after the first POST. I\'m creating a scheduling application, which is X number of days, with rooms, and time slots for the rooms.

<
相关标签:
2条回答
  • 2021-02-20 17:08

    I think You had model for days collection with date attribute which had unique index date_1.

    Now You've removed it but collection still has that index.

    so that's why it says:

    duplicate key error collection: .days index: date_1 dup key: { : null }

    it means You're inserting another record where date attribute is also null.

    log in to mongodb from console and try to do this:

    db.collectionNameHere.getIndexes();
    db.collectionNameHere.dropIndex('date_1');
    db.collectionNameHere.getIndexes();
    

    p.s. feel free to provide any additional data in Your question or in comments, to help me/us to solve Your issue.

    0 讨论(0)
  • 2021-02-20 17:16

    drop the collection and run again

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