jstests/core/collmod_convert_to_unique_violations.js
// Checks that the violations match what we expect.
Checks that the violations match what we expect.
Checks that the violations match what we expect .
function assertFailedWithViolations(keyPattern, violations) {
    assert.commandWorked(
        db.runCommand({collMod: collName, index: {keyPattern: keyPattern, prepareUnique: true}}));
    const result =
        db.runCommand({collMod: collName, index: {keyPattern: keyPattern, unique: true}});
    assert.commandFailedWithCode(result, ErrorCodes.CannotConvertIndexToUnique);
    assert.eq(
        bsonWoCompare(sortViolationsArray(result.violations), sortViolationsArray(violations)),
        0,
        tojson(result));
    assert.commandWorked(
        db.runCommand({collMod: collName, index: {keyPattern: keyPattern, prepareUnique: false}}));
}
function assertFailedWithViolations ( keyPattern , violations ) { assert . commandWorked ( db . runCommand ( { collMod : collName , index : { keyPattern : keyPattern , prepareUnique : true } } ) ) ; const result = db . runCommand ( { collMod : collName , index : { keyPattern : keyPattern , unique : true } } ) ; assert . commandFailedWithCode ( result , ErrorCodes . CannotConvertIndexToUnique ) ; assert . eq ( bsonWoCompare ( sortViolationsArray ( result . violations ) , sortViolationsArray ( violations ) ) , 0 , tojson ( result ) ) ; assert . commandWorked ( db . runCommand ( { collMod : collName , index : { keyPattern : keyPattern , prepareUnique : false } } ) ) ; }
Checks that the violations match what we expect.
Checks that the violations match what we expect .
// First sets 'prepareUnique' before converting the index to unique. // Resets 'prepareUnique'.