Instance Method
createIndex(inDB:index:eventLoopGroup:)
Creates a new Mango index in a specified database.
func createIndex(inDB dbName: String, index: MangoIndex, eventLoopGroup: (any EventLoopGroup)? = nil) async throws -> MangoCreateIndexResponse
Parameters
- dbName
The name of the database.
- index
The MangoIndex to create.
- eventLoopGroup
An optional EventLoopGroup for executing network operations.
Return Value
A MangoCreateIndexResponse indicating the result of the operation.
Discussion
Throws
A CouchDBClientError if the operation fails.
Example Usage:
// Define a Mango index
let index = MangoIndex(
fields: ["name"],
name: "name-index",
type: "json"
)
// Create the index in the database
let response = try await couchDBClient.createIndex(inDB: "myDatabase", index: index)
print(response.result) // Should print "created" or "exists"
Note
Ensure that the CouchDB server is running and accessible before calling this function. Handle thrown errors appropriately, especially for index creation conflicts or server issues.