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

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -