E11000 double error index: when creating a unique index

I run the query below in robomongo. Does the bot give an error as shown below? I am really trying to remove duplicates in url field using this query. Are there any problems with my request?

db.dummy_data.createIndex({"url":1},{unique:true},{dropDups:true})

My E11000 error duplicating the key error index: mydb.dummy_data. $ Url_1 dup key: {"some url"}

+4
source share
1 answer

Therefore, when your syntax is fixed due to misuse:

db.dummy_data.ensureIndex({ "url": 1},{ "unique": true, "dropDups": true })

It is reported that you are still receiving an error message, but a new one:

{ "connectionId": 336, "err": " dropDups = true", "code": 10092, "n": 0, "ok": 1}

google, :

, ,

, 1000000. , , : " , , ram ". ( == 1000000), , makeIndex {dropDups: true} reimport .

, .

, , . :

db.newdata.ensureIndex({ "url": 1},{ "unique": true, "dropDups": true });

db.dummy_data.find().forEach(function(doc) {
    db.newdata.insert(doc);
});

:

db.newdata.ensureIndex({ "url": 1},{ "unique": true, "dropDups": true });

var bulk = db.newdata.initializeUnOrderedBulkOp();
var counter = 0;

db.dummy_data.find().forEach(function(doc) {
    counter++;
    bulk.insert( doc );

    if ( counter % 1000 == 0 ) {
        bulk.execute();
        bulk = db.newdata.initializeUnOrderedBulkOp();
    }
});

if ( counter % 1000 != 0 )
    bulk.execute();

, , , -, .

+3

All Articles