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 err

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Switch the ledger to CouchDB (ledger.state.stateDatabase: gocouchdb) and configure the CouchDB address.
  2. Replace paginated rich queries with GetStateByRangeWithPagination, which is supported on LevelDB.
  3. Gate the rich-query code path on deployment configuration before calling it.
  4. 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

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


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