Instance Method
explain(inDB:query:eventLoopGroup:)
Explains a Mango query in a specified database.
func explain(inDB dbName: String, query: MangoQuery, eventLoopGroup: (any EventLoopGroup)? = nil) async throws -> MangoExplainResponse
Parameters
- dbName
The name of the database.
- query
The MangoQuery to explain.
- eventLoopGroup
An optional EventLoopGroup for executing network operations.
Return Value
A MangoExplainResponse containing the query execution plan.
Discussion
Throws
A CouchDBClientError if the operation fails.
Example Usage:
// Define a Mango query
let query = MangoQuery(selector: ["name": .string("Sam")])
// Explain the query execution plan
let explainResponse = try await couchDBClient.explain(inDB: "myDatabase", query: query)
print(explainResponse.index) // Shows which index will be used
print(explainResponse.selector) // Shows the query selector
Note
Ensure that the CouchDB server is running and accessible before calling this function. Handle thrown errors appropriately, especially for query or index issues.