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

  1. Configure CouchDB as the state database: set ledger.state.stateDatabase: gocouchdb in core.yaml and provide CouchDB connection settings.
  2. Rewrite the query logic using GetStateByRange or composite keys, which work on LevelDB.
  3. Feature-detect in chaincode: avoid GetQueryResult paths when CouchDB is not configured.
  4. 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

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


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/6b5271478eed4098. Report an issue: GitHub.