Unique indexes prevent multiple documents to match the same index key:


> db.cities.createIndex( { country_code: 1, name: 1 }, *{ unique: true }* );
You can force the index with dropDups (This could delete a lot of data!):


> db.cities.createIndex( { country_code: 1, name: 1 },
                         { unique: true, *|f10000|dropDups : true|* } );