Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4607688
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:44:18+00:00 2026-05-22T00:44:18+00:00

I am working on a MongoDB-backed authentication module for my asp.net application. The MongoDB

  • 0

I am working on a MongoDB-backed authentication module for my asp.net application. The MongoDB database has a collections of users where I store login information – username, email and password. Both username and email are set to be unique:

users.ensureIndex({email:1}, {unique:1})
users.ensureIndex({uname:1}, {unique:1})

Now, if I try to insert a record with existing uname or email, i get a MongoDB exception:

Safemode detected an error: E11000 duplicate key error index: 
authdb.users.$email_1  dup key: { : "test@test.com" } 
(response: { "err" : "E11000 duplicate key error index: authdb.users.$email_1  
dup key: { : \"test@test.com\" }", "code" : 11000, "n" : 0, "connectionId" : 9, 
"ok" : 1.0 })

I need to tell the user that the username or email they entered already exists, but the whole exception is just a blob of text, and to see what’s going on I have to guess by looking whether “$email” or “$uname” are in the error message text. Is there some sort of parser for MongoDB exceptions which would help me detect what the exception is for?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:44:19+00:00Added an answer on May 22, 2026 at 12:44 am

    I have created a feature request in MongoDB’s bug tracker to add extra fields to the output of getLastError on duplicate key errors. Please vote for it at https://jira.mongodb.org/browse/SERVER-3069.

    Until that is implemented, for your use case you can just check if the err string contains either “email” or “uname” and retrieve the duplicated value from the document you just tried to insert. It’s not as elegant as it could be, but it should work for now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with an Oracle 9i database from an ASP.NET 2.0 (VB) application using OLEDB.
As I am working on .Net windows form application, we're using MongoDB for back-end
I'm working with a database MongoDB and due to the high consumption of resources
I'm working on a prototype to use a document database (currently MongoDB, may change)
During working on one c++ project we decided to use MongoDB database for storing
I'm working on creating scripts using python, mongodb and the pymongo module to fetch
I'm working on an application where the end user defines what columns a database
I've googled around but couldn't find a working MongoDB viewer or data browser. An
I've just started working with mongodb got a perl script that parses a twitter
I'm working on a Python/MongoDB project in both my computer at home and my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.