hyperledger/fabric · error
ExecuteQuery not supported for leveldb
Error message
ExecuteQuery not supported for leveldb
What it means
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.
Source
Thrown at core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb.go:177
}
// GetStateRangeScanIteratorWithPagination implements method in VersionedDB interface
func (vdb *versionedDB) GetStateRangeScanIteratorWithPagination(namespace string, startKey string, endKey string, pageSize int32) (statedb.QueryResultsIterator, error) {
dataStartKey := encodeDataKey(namespace, startKey)
dataEndKey := encodeDataKey(namespace, endKey)
if endKey == "" {
dataEndKey[len(dataEndKey)-1] = lastKeyIndicator
}
dbItr, err := vdb.db.GetIterator(dataStartKey, dataEndKey)
if err != nil {
return nil, err
}
return newKVScanner(namespace, dbItr, pageSize), nil
}
// ExecuteQuery implements method in VersionedDB interface
func (vdb *versionedDB) ExecuteQuery(namespace, query string) (statedb.ResultsIterator, error) {
return nil, errors.New("ExecuteQuery not supported for leveldb")
}
// ExecuteQueryWithPagination implements method in VersionedDB interface
func (vdb *versionedDB) ExecuteQueryWithPagination(namespace, query, bookmark string, pageSize int32) (statedb.QueryResultsIterator, error) {
return nil, errors.New("ExecuteQueryWithMetadata not supported for leveldb")
}
// ApplyUpdates implements method in VersionedDB interface
func (vdb *versionedDB) ApplyUpdates(batch *statedb.UpdateBatch, height *version.Height) error {
dbBatch := vdb.db.NewUpdateBatch()
namespaces := batch.GetUpdatedNamespaces()
for _, ns := range namespaces {
updates := batch.GetUpdates(ns)
for k, vv := range updates {
dataKey := encodeDataKey(ns, k)
logger.Debugf("Channel [%s]: Applying key(string)=[%s] key(bytes)=[%#v]", vdb.dbName, string(dataKey), dataKey)
if vv.Value == nil {View on GitHub (pinned to 2736b63f8f)
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.
Example fix
// before
iter, err := stub.GetQueryResult("{\"selector\":{\"owner\":\"a\"}}") // fails on leveldb
// after
iter, err := stub.GetStateByRange("", "~") // range scan works on any statedb Defensive patterns
Strategy: fallback
Validate before calling
// config check before deploying chaincode // core.yaml: ledger.state.stateDatabase must be "gocouchdb" to use GetQueryResult
Try / catch
iter, err := stub.GetQueryResult(query)
if err != nil {
// fall back to range scan for leveldb networks
return stub.GetStateByRange(startKey, endKey)
} Prevention
- 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
When it happens
Trigger: Chaincode calls GetQueryResult (which routes to ExecuteQuery) while the network's state database is configured as LevelDB (default).
Common situations: 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.
Related errors
- ExecuteQueryWithMetadata not supported for leveldb
- Could not get block file info for current block file from db
- Could not save next block file info to db: %s
- error in block index: %s
- block hashes not maintained in index
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/6b5271478eed4098.
Report an issue: GitHub.