diff options
Diffstat (limited to 'jstests/core/ddl/rename_collection_long_name.js')
-rw-r--r-- | jstests/core/ddl/rename_collection_long_name.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/jstests/core/ddl/rename_collection_long_name.js b/jstests/core/ddl/rename_collection_long_name.js new file mode 100644 index 00000000000..becf929a189 --- /dev/null +++ b/jstests/core/ddl/rename_collection_long_name.js @@ -0,0 +1,43 @@ +// Test for SERVER-7017 +// We are allowed to rename a collection when one of its indexes will generate a namespace +// that is greater than 120 chars. To do this we create a long index name and try +// and rename the collection to one with a much longer name. We use the test database +// by default and we add this here to ensure we are using it +// @tags: [ +// assumes_no_implicit_collection_creation_after_drop, +// requires_non_retryable_commands, +// ] + +(function() { +'use strict'; + +const testDB = db.getSiblingDB("test"); +const srcName = "renameSRC"; +const src = testDB.getCollection(srcName); +const dstName = "dest4567890123456789012345678901234567890123456789012345678901234567890"; +const dst = testDB.getCollection(dstName); + +src.drop(); +dst.drop(); + +src.createIndex({ + "name": 1, + "date": 1, + "time": 1, + "renameCollection": 1, + "mongodb": 1, + "testing": 1, + "data": 1 +}); + +// Newly created index + _id index in original collection (+ hashed _id in case of sharded suite) +const originalNumberOfIndexes = src.getIndexes().length; + +// Should succeed in renaming collection as the long index namespace is acceptable. +assert.commandWorked(src.renameCollection(dstName), "Rename collection with long name failed"); + +assert.eq(0, src.getIndexes().length, "No indexes expected on already renamed collection"); +assert.eq(originalNumberOfIndexes, + dst.getIndexes().length, + "Expected exactly same number of indexes of source collection before rename"); +})(); |