hyperledger/fabric · error
ExecuteQueryWithMetadata not supported for leveldb
Error message
ExecuteQueryWithMetadata not supported for leveldb
What it means
ExecuteQueryWithPagination is the paginated variant of rich queries; like ExecuteQuery it is unimplemented on LevelDB and always returns an error (note the message says 'ExecuteQueryWithMetadata', a naming quirk). Pagination over Mango-style queries requires CouchDB.
Source
Thrown at core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb.go:182
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 {
dbBatch.Delete(dataKey)
} else {
encodedVal, err := encodeValue(vv)
if err != nil {
return errView on GitHub (pinned to 2736b63f8f)
Solutions
- Switch the ledger to CouchDB (ledger.state.stateDatabase: gocouchdb) and configure the CouchDB address.
- Replace paginated rich queries with GetStateByRangeWithPagination, which is supported on LevelDB.
- Gate the rich-query code path on deployment configuration before calling it.
- Refactor the data model to use composite keys so range scans can replace queries.
Example fix
// before
iter, err := stub.GetQueryResultWithPagination(query, "", 10)
// after
iter, err := stub.GetStateByRangeWithPagination("", "~", 10) Defensive patterns
Strategy: fallback
Validate before calling
// ensure CouchDB backing before paginated rich queries // ledger.state.stateDatabase == "gocouchdb" required
Try / catch
iter, err := stub.GetQueryResultWithPagination(query, bookmark, pageSize)
if err != nil {
return stub.GetStateByRangeWithPagination("", "~", pageSize)
} Prevention
- Prefer GetStateByRangeWithPagination for pagination that works on both LevelDB and CouchDB
- Keep chaincode feature usage aligned with the deployment's statedb choice
- Add integration tests against both leveldb and couchdb configurations
When it happens
Trigger: Chaincode calls GetQueryResultWithPagination while the state database is LevelDB.
Common situations: Same as ExecuteQuery errors: chaincode assuming CouchDB features on a default LevelDB network; sample/production config drift where rich-query code paths run without CouchDB configured.
Related errors
- ExecuteQuery 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/26c0596f43867f6d.
Report an issue: GitHub.