diff options
author | Judah Schvimer <judah@mongodb.com> | 2016-07-06 17:38:10 -0400 |
---|---|---|
committer | Judah Schvimer <judah@mongodb.com> | 2016-07-06 17:38:10 -0400 |
commit | b3611e663fb40505340589fd75fa5d504829c609 (patch) | |
tree | b919f526a0e36f4ee93f6e16f911bd25c7dbb6c9 | |
parent | 8833b39af63a926fe7c8538e26666f3c2f20855b (diff) | |
download | mongo-b3611e663fb40505340589fd75fa5d504829c609.tar.gz |
SERVER-24883 cloner should not create _id index when original collection doesn't have one
-rw-r--r-- | jstests/core/copydatabase_no_id_index.js | 23 | ||||
-rw-r--r-- | src/mongo/db/cloner.cpp | 10 |
2 files changed, 32 insertions, 1 deletions
diff --git a/jstests/core/copydatabase_no_id_index.js b/jstests/core/copydatabase_no_id_index.js new file mode 100644 index 00000000000..2cd1225d78b --- /dev/null +++ b/jstests/core/copydatabase_no_id_index.js @@ -0,0 +1,23 @@ +/** + * This test creates a collection with autoIndexId: false. It then copies the database and expects + * the new collection to not have an _id index either. + */ + +(function() { + "use strict"; + var db1 = db.getSiblingDB('copydatabase_no_id_index'); + var db2 = db.getSiblingDB('copydatabase_no_id_index2'); + db1.dropDatabase(); + db2.dropDatabase(); + + assert.commandWorked(db1.runCommand({create: 'foo', autoIndexId: false})); + assert.writeOK(db1.foo.insert({a: 1})); + assert.eq(db1.foo.getIndexes().length, 0); + + assert.commandWorked(db1.copyDatabase('copydatabase_no_id_index', 'copydatabase_no_id_index2')); + + assert.eq(db1.foo.count(), 1); + assert.eq(db1.foo.getIndexes().length, 0); + assert.eq(db2.foo.count(), 1); + assert.eq(db2.foo.getIndexes().length, 0); +})();
\ No newline at end of file diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index 91fa3d94b75..9d4a5165424 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -618,7 +618,15 @@ Status Cloner::copyDb(OperationContext* txn, uassert(18645, str::stream() << "database " << toDBName << " dropped during clone", db); Collection* c = db->getCollection(to_name); - if (c && !c->getIndexCatalog()->haveIdIndex(txn)) { + bool autoIndexId = true; + auto status = + bsonExtractBooleanFieldWithDefault(options, "autoIndexId", true, &autoIndexId); + if (!status.isOK()) { + return status; + } + + if (c && !c->getIndexCatalog()->haveIdIndex(txn) && autoIndexId) { + // We need to drop objects with duplicate _ids because we didn't do a true // snapshot and this is before applying oplog operations that occur during the // initial sync. |