0

I have 9 million document and each document 119 fields

{  "_id" : 0,"field_1" : "value" , .....,"field_118" : "value" }
...
...
...
{  "_id" : 8999999,"field_1" : "value" , .....,"field_118" : "value" }

I tried

db.collection.ensureIndex({"field_1":1,"field_2":1,....,"field_118":1}, {unique : true, dropDups : true})

i got a error message

"errmsg" : "namespace name generated from index name \"....(fields)..\" is too long (127 byte max)", "code" : 67

how to solve ?

mohamedzajith
  • 387
  • 1
  • 4
  • 15
  • 1
    The dropDups option has been deprecated since MongoDB 2.6... Which mongodb are you using? – ZeMoon Aug 12 '15 at 14:06
  • mongoDB version 2.6.10 – mohamedzajith Aug 12 '15 at 14:10
  • The dropDups option will not work. You will need to manually remove the duplicate fields or use a script. – ZeMoon Aug 12 '15 at 14:11
  • I find it hard to belive that *119 fields* form a unqiue set of values in combination. At most you only likely have a few fields that actually make a document "unique" and can otherwise deal with discarding or otherwise dealing with the other varying values. – Blakes Seven Aug 12 '15 at 14:28
  • possible duplicate of [remove dups from mongodb](http://stackoverflow.com/questions/31557053/remove-dups-from-mongodb) – Blakes Seven Aug 12 '15 at 14:29
  • i want to scrip file and http://stackoverflow.com/questions/31557053/remove-dups-from-mongodb dose not work – mohamedzajith Aug 13 '15 at 12:55

1 Answers1

1

The error message says that the auto-generated name of your index has exceeded the index name length.

From documentation:

Index Name Length Fully qualified index names, which includes the namespace and the dot separators (i.e. ..$), cannot be longer than 128 characters.

By default, is the concatenation of the field names and index type. You can explicitly specify the to the createIndex() method to ensure that the fully qualified index name does not exceed the limit.

So, specify your own index name for your index in ensureIndex or createIndex options parameter:

{unique : true, name: myAwesomeIndex}
Community
  • 1
  • 1
Xavier Egea
  • 4,712
  • 3
  • 25
  • 39