E11000 duplicate key error index in mongodb mongoose

前端 未结 25 2002
自闭症患者
自闭症患者 2020-11-22 05:49

Following is my user schema in user.js model -

var userSchema = new mongoose.Schema({
    local: {
        name: { type: String },
         


        
25条回答
  •  滥情空心
    2020-11-22 06:35

    Drop you database, then it will work.

    You can perform the following steps to drop your database

    step 1 : Go to mongodb installation directory, default dir is "C:\Program Files\MongoDB\Server\4.2\bin"

    step 2 : Start mongod.exe directly or using command prompt and minimize it.

    step 3 : Start mongo.exe directly or using command prompt and run the following command

    i) use yourDatabaseName (use show databases if you don't remember database name)

    ii) db.dropDatabase()

    This will remove your database. Now you can insert your data, it won't show error, it will automatically add database and collection.

提交回复
热议问题