{"record":{"id":"f4d86d51871ba4c7","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-retrieve-item-from-mongodb-like-storage","errorCode":null,"errorMessage":"Failed to retrieve item from MongoDB-like storage","messagePattern":"Failed to retrieve item from MongoDB-like storage","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/MongoStore.java","lineNumber":117,"sourceCode":"\t}\n\n\t@Override\n\tpublic Optional<StoreItem> getItem(List<String> namespace, String key) {\n\t\tvalidateGetItem(namespace, key);\n\n\t\tlock.readLock().lock();\n\t\ttry {\n\t\t\tString documentId = createDocumentId(namespace, key);\n\t\t\tMap<String, Object> doc = mongoLikeCollection.get(documentId);\n\n\t\t\tif (doc == null) {\n\t\t\t\treturn Optional.empty();\n\t\t\t}\n\n\t\t\treturn Optional.of(documentToStoreItem(doc));\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new RuntimeException(\"Failed to retrieve item from MongoDB-like storage\", e);\n\t\t}\n\t\tfinally {\n\t\t\tlock.readLock().unlock();\n\t\t}\n\t}\n\n\t@Override\n\tpublic boolean deleteItem(List<String> namespace, String key) {\n\t\tvalidateDeleteItem(namespace, key);\n\n\t\tlock.writeLock().lock();\n\t\ttry {\n\t\t\tString documentId = createDocumentId(namespace, key);\n\t\t\treturn mongoLikeCollection.remove(documentId) != null;\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new RuntimeException(\"Failed to delete item from MongoDB-like storage\", e);\n\t\t}","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/MongoStore.java#L99-L135","documentation":"MongoStore.getItem fetches a document by namespace+key and converts it back to a StoreItem; any exception (other than the not-found path returning Optional.empty()) is wrapped in RuntimeException('Failed to retrieve item from MongoDB-like storage') under the read lock.","triggerScenarios":"store.getItem(namespace, key) where createDocumentId or documentToStoreItem throws — malformed stored document missing required fields, wrong value type in the map, or null namespace/key.","commonSituations":"Reading data written by an older store version with a different document schema; manual edits/corruption of stored maps; type changes in value serialization between releases.","solutions":["Check getCause() to see if deserialization (documentToStoreItem) failed","Clear or migrate incompatible documents written by older versions","Validate namespace/key are non-null before calling getItem","Use searchItems or delete+rewrite the corrupted entry"],"exampleFix":"// before\nStoreItem item = store.getItem(ns, key).orElseThrow();\n// after\ntry {\n    StoreItem item = store.getItem(ns, key).orElseThrow();\n} catch (RuntimeException e) {\n    log.warn(\"corrupt item {}, removing\", key, e.getCause());\n    store.deleteItem(ns, key);\n}","handlingStrategy":"try-catch","validationCode":"if (namespace == null || key == null || key.isBlank()) {\n    throw new IllegalArgumentException(\"namespace and key required\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Optional<StoreItem> item = store.getItem(namespace, key);\n    return item;\n} catch (RuntimeException e) {\n    logger.warn(\"getItem failed (corrupt doc?): {}\", e.getCause());\n    return Optional.empty();\n}","preventionTips":["Keep document schema stable across versions; migrate on upgrade","Treat Optional.empty and exceptions separately","Detect and rewrite corrupted entries"],"tags":["store","database","read"],"backgroundTag":"database-query-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}