{"record":{"id":"6b5271478eed4098","repo":"hyperledger/fabric","slug":"executequery-not-supported-for-leveldb","errorCode":null,"errorMessage":"ExecuteQuery not supported for leveldb","messagePattern":"ExecuteQuery not supported for leveldb","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb.go","lineNumber":177,"sourceCode":"}\n\n// GetStateRangeScanIteratorWithPagination implements method in VersionedDB interface\nfunc (vdb *versionedDB) GetStateRangeScanIteratorWithPagination(namespace string, startKey string, endKey string, pageSize int32) (statedb.QueryResultsIterator, error) {\n\tdataStartKey := encodeDataKey(namespace, startKey)\n\tdataEndKey := encodeDataKey(namespace, endKey)\n\tif endKey == \"\" {\n\t\tdataEndKey[len(dataEndKey)-1] = lastKeyIndicator\n\t}\n\tdbItr, err := vdb.db.GetIterator(dataStartKey, dataEndKey)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn newKVScanner(namespace, dbItr, pageSize), nil\n}\n\n// ExecuteQuery implements method in VersionedDB interface\nfunc (vdb *versionedDB) ExecuteQuery(namespace, query string) (statedb.ResultsIterator, error) {\n\treturn nil, errors.New(\"ExecuteQuery not supported for leveldb\")\n}\n\n// ExecuteQueryWithPagination implements method in VersionedDB interface\nfunc (vdb *versionedDB) ExecuteQueryWithPagination(namespace, query, bookmark string, pageSize int32) (statedb.QueryResultsIterator, error) {\n\treturn nil, errors.New(\"ExecuteQueryWithMetadata not supported for leveldb\")\n}\n\n// ApplyUpdates implements method in VersionedDB interface\nfunc (vdb *versionedDB) ApplyUpdates(batch *statedb.UpdateBatch, height *version.Height) error {\n\tdbBatch := vdb.db.NewUpdateBatch()\n\tnamespaces := batch.GetUpdatedNamespaces()\n\tfor _, ns := range namespaces {\n\t\tupdates := batch.GetUpdates(ns)\n\t\tfor k, vv := range updates {\n\t\t\tdataKey := encodeDataKey(ns, k)\n\t\t\tlogger.Debugf(\"Channel [%s]: Applying key(string)=[%s] key(bytes)=[%#v]\", vdb.dbName, string(dataKey), dataKey)\n\n\t\t\tif vv.Value == nil {","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb.go#L159-L195","documentation":"The LevelDB statedb implementation does not implement CouchDB rich (Mango) queries, so ExecuteQuery always fails. Rich queries are a CouchDB-only capability; LevelDB supports only range reads via GetStateByRange and partial composite-key scans.","triggerScenarios":"Chaincode calls GetQueryResult (which routes to ExecuteQuery) while the network's state database is configured as LevelDB (default).","commonSituations":"Deploying chaincode that uses GetQueryResult on a network without switching core.yaml's ledger.state.stateDatabase to CouchDB; running tests against the default leveldb provider; porting a CouchDB-based chaincode to a LevelDB environment.","solutions":["Configure CouchDB as the state database: set ledger.state.stateDatabase: gocouchdb in core.yaml and provide CouchDB connection settings.","Rewrite the query logic using GetStateByRange or composite keys, which work on LevelDB.","Feature-detect in chaincode: avoid GetQueryResult paths when CouchDB is not configured.","If CouchDB is required for the use case, redeploy the network with CouchDB backing."],"exampleFix":"// before\niter, err := stub.GetQueryResult(\"{\\\"selector\\\":{\\\"owner\\\":\\\"a\\\"}}\") // fails on leveldb\n// after\niter, err := stub.GetStateByRange(\"\", \"~\") // range scan works on any statedb","handlingStrategy":"fallback","validationCode":"// config check before deploying chaincode\n// core.yaml: ledger.state.stateDatabase must be \"gocouchdb\" to use GetQueryResult","typeGuard":null,"tryCatchPattern":"iter, err := stub.GetQueryResult(query)\nif err != nil {\n  // fall back to range scan for leveldb networks\n  return stub.GetStateByRange(startKey, endKey)\n}","preventionTips":["Document that the chaincode requires CouchDB and fail deployment checks otherwise","Avoid GetQueryResult in chaincode meant to run on any statedb; prefer GetStateByRange/composite keys","Verify network config (stateDatabase) before invoking rich-query paths"],"tags":["leveldb","rich-query","unsupported-operation","statedb"],"backgroundTag":"operation-not-supported","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}