I am creating an application with a user registration page using Nodejs, Express.js & MongoDB as DB. I have created the schema, and API end points to test its functioning I used the Postman application, for which I am not getting the response and I get the below error message in the npm terminal
NOTE; My DB itself is empty I don’t have any data in it, I am just testing the API by sending the data in JSON format through Postman and this “duplicate” error is coming.
Error as seen in Npm terminal:
MongoServerError: E11000 duplicate key error collection: AuthDB.users index: username_1 dup key: { username: “Prasath2000” }
{
index: 0,
code: 11000,
keyPattern: { username: 1 },
keyValue: { username: ‘Prasath2000’ },
[Symbol(errorLabels)]: Set(0) {}
}
Node.js v19.8.1
[nodemon] app crashed - waiting for file changes before starting…
[nodemon] restarting due to changes…
[nodemon] starting node index.js
Server is running at http://localhost:8800
Connected to the DB
My DB: I don’t even have any data , how its duplicated then?
My Schema: Username is kept Unique
username: {
type: String,
required: true,
unique: true
},
Postman query:
{
“firstName”: “Prasath”,
“lastName”: “V”,
“username”: “Prasath2000”,
“email”: “prasathvenkat2000@gmail.com”,
“password”: “Prasath@2000”
}
Plz help me!
