javascript - MongoDB query to remove duplicate documents from a collection -


i take data search box , insert mongodb document using regular insert query. data stored in collection word "cancer" in following format unique "_id".

{   "_id": {     "$oid": "553862fa49aa20a608ee2b7b"   },   "0": "c",   "1": "a",   "2": "n",   "3": "c",   "4": "e",   "5": "r" } 

each document has single word stored in same format above. have many documents such. now, want remove duplicate documents collection. unable figure out way that. me.

an easy solution in mongo shell: `

use your_db db.your_collection.createindex({'1': 1, '2': 1, '3': 1, etc until reach maximum expected letter count}, {unique: true, dropdups: true, sparse:true, name: 'dropdups'}) db.your_collection.dropindex('dropdups') 

notes:

  • if have many documents expect procedure take long time
  • be careful remove documents in place, better clone collection first , try there.

Popular posts from this blog

javascript - Js, document.getElementById("ID").innerHTML, error -

jquery - jqGrid update specific column data with out refreshing the entire column? -

objective c - Is there a way in OCMockito to make stubs fail when an unknown method is called? -