- Indexes >
- Indexing Tutorials >
- Index Management Tutorials >
- Modify an Index
Modify an Index¶
To modify an existing index, you need to drop and recreate the index.
Create a unique index.¶
Use the createIndex() method create a unique
index.
The method returns a document with the status of the results. The method only creates an index if the index does not already exist. See Create an Index and Index Creation Tutorials for more information on creating indexes.
Attempt to modify the index.¶
To modify an existing index, you cannot just re-issue the
createIndex() method with the updated
specification of the index.
For example, the following operation attempts to remove the
unique constraint from the previously created index by using the
createIndex() method.
The status document returned by the operation shows an error.
Drop the index.¶
To modify the index, you must drop the index first.
The method returns a document with the status of the operation. Upon
successful operation, the ok field in the returned document should
specify a 1. See Remove Indexes for more
information about dropping indexes.
Recreate the index without the unique constraint.¶
Recreate the index without the unique constraint.
The method returns a document with the status of the results. Upon
successful operation, the returned document should show the
numIndexesAfter to be greater than numIndexesBefore by one.
See also