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

  • SEARCH
  • Home
  • 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 9305249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:53:10+00:00 2026-06-18T23:53:10+00:00

I have tons of data in my database. and i have so many duplicates

  • 0

I have tons of data in my database. and i have so many duplicates in it. I want to remove all these duplicates and keep only one data from it,

For example i have data like this in my login object

id name

123 abc

124 abc

125 abc

126 abc

127 pqr

128 pqs

i want to keep only one user whose name is ‘abc’ and remove all the other users whose name is ‘abc’
How can i achieve it in mongodb
thanks in advance

  • 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-06-18T23:53:11+00:00Added an answer on June 18, 2026 at 11:53 pm

    One method is to actually create a unique index on the users name and give it an option to dropDups: http://docs.mongodb.org/manual/core/indexes/#drop-duplicates

    So for your example:

    db.user.ensureIndex({name:1},{unique:1,dropDups:true})
    

    Would create a unique index on the name that will drop all other duplicates.

    Of course the double benefit of this is that you now have a unique index on the name ensuring that you don’t get duplicates again.

    You can also do this via clent side but it is likely to be slower than doing it by building an index.

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

Sidebar

Related Questions

i have tons of data that i would like to highlight only those cell
I have an XML file and I want to retrieve data from it so
I have tons of data in directory called reports. While doing git merge with
How can I copy all the records from a table in a MySql database
I have a script that extracts several rows of data from an external file,
I have a warehouse table with 16 tons of data in it. I have
When is it okay to have duplication of data in your database? I'm working
I have a situation where I need to keep track of all changes to
I have a several C# console applications that basically parse tons of data in
I have a console app that opens an oleDBConnection to access some data from

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.