Duplicate Key Error : "MongoServerError: E11000 duplicate key error collection"

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!

Hi @Prasath_V

The collection in the screenshot is capital U on users: AuthDB.Users while the error pasted (please use code blocks when posting code/errors/output) is lowercase u users AuthDB.users

I think Compass and the Node app are connecting to different clusters, or the Compass view needs refreshing. The one node is connecting to certainly has a duplicate.

What exactly was causing this, did that solution worked for u?