{"record":{"id":"26c0596f43867f6d","repo":"hyperledger/fabric","slug":"executequerywithmetadata-not-supported-for-leveldb","errorCode":null,"errorMessage":"ExecuteQueryWithMetadata not supported for leveldb","messagePattern":"ExecuteQueryWithMetadata not supported for leveldb","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb.go","lineNumber":182,"sourceCode":"\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 {\n\t\t\t\tdbBatch.Delete(dataKey)\n\t\t\t} else {\n\t\t\t\tencodedVal, err := encodeValue(vv)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb.go#L164-L200","documentation":"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.","triggerScenarios":"Chaincode calls GetQueryResultWithPagination while the state database is LevelDB.","commonSituations":"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.","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."],"exampleFix":"// before\niter, err := stub.GetQueryResultWithPagination(query, \"\", 10)\n// after\niter, err := stub.GetStateByRangeWithPagination(\"\", \"~\", 10)","handlingStrategy":"fallback","validationCode":"// ensure CouchDB backing before paginated rich queries\n// ledger.state.stateDatabase == \"gocouchdb\" required","typeGuard":null,"tryCatchPattern":"iter, err := stub.GetQueryResultWithPagination(query, bookmark, pageSize)\nif err != nil {\n  return stub.GetStateByRangeWithPagination(\"\", \"~\", pageSize)\n}","preventionTips":["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"],"tags":["leveldb","rich-query","pagination","unsupported-operation"],"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"}