|
When creating a duplicate normal index twice, you simply get a notification in the command return structure that tells you no indexes were created:
> db.col1.runCommand({ 'createIndexes' : 'col1', indexes: [ { name: "e_1", key: { e: 1 } } ] } );
|
{
|
"createdCollectionAutomatically" : false,
|
"numIndexesBefore" : 2,
|
"numIndexesAfter" : 3,
|
"ok" : 1
|
}
|
> db.col1.runCommand({ 'createIndexes' : 'col1', indexes: [ { name: "e_1", key: { e: 1 } } ] } );
|
{
|
"numIndexesBefore" : 3,
|
"note" : "all indexes already exist",
|
"noChangesMade" : true,
|
"ok" : 1
|
}
|
But when we do this with a "text" column, then it fails with an error:
|
> db.col1.runCommand({ 'createIndexes' : 'col1', indexes: [ { name: "d_1", key: { d: 'text' } } ] } );
|
{
|
"createdCollectionAutomatically" : true,
|
"numIndexesBefore" : 1,
|
"numIndexesAfter" : 2,
|
"ok" : 1
|
}
|
> db.col1.runCommand({ 'createIndexes' : 'col1', indexes: [ { name: "d_1", key: { d: 'text' } } ] } );
|
{
|
"ok" : 0,
|
"errmsg" : "Trying to create an index with same name d_1 with different key spec { d: \"text\" } vs existing spec { _fts: \"text\", _ftsx: 1 }",
|
"code" : 67
|
}
|
|