{"record":{"id":"7c7ae3a139d16e01","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-delete-item-from-mongodb-like-storage","errorCode":null,"errorMessage":"Failed to delete item from MongoDB-like storage","messagePattern":"Failed to delete 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":134,"sourceCode":"\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}\n\t\tfinally {\n\t\t\tlock.writeLock().unlock();\n\t\t}\n\t}\n\n\t@Override\n\tpublic StoreSearchResult searchItems(StoreSearchRequest searchRequest) {\n\t\tvalidateSearchItems(searchRequest);\n\n\t\tlock.readLock().lock();\n\t\ttry {\n\t\t\tList<StoreItem> allItems = getAllItems();\n\n\t\t\t// Apply filters\n\t\t\tList<StoreItem> filteredItems = allItems.stream()\n\t\t\t\t.filter(item -> matchesSearchCriteria(item, searchRequest))\n\t\t\t\t.collect(Collectors.toList());","sourceCodeStart":116,"sourceCodeEnd":152,"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#L116-L152","documentation":"MongoStore.deleteItem computes the document id and removes it from mongoLikeCollection; any exception is wrapped in RuntimeException('Failed to delete item from MongoDB-like storage') under the write lock. The boolean return (removed != null) is only reached if no exception occurs.","triggerScenarios":"store.deleteItem(namespace, key) where createDocumentId throws on invalid namespace/key, or the backing collection's remove operation fails; also any unexpected RuntimeException inside the try block.","commonSituations":"Null/blank namespace or key reaching document-id construction; concurrent structural modification of the underlying map if a non-thread-safe collection is substituted; migration to a real MongoDB where remove hits connection errors.","solutions":["Validate namespace/key are non-null and non-blank before deleteItem","Inspect getCause() for the root exception","Confirm the backing collection implementation is thread-safe","If backed by real MongoDB, check connection health and retry the delete"],"exampleFix":"// before\nboolean removed = store.deleteItem(ns, key); // key may be null\n// after\nif (key == null || key.isBlank()) {\n    throw new IllegalArgumentException(\"key required\");\n}\nboolean removed = store.deleteItem(ns, key);","handlingStrategy":"validation","validationCode":"if (key == null || key.isBlank()) throw new IllegalArgumentException(\"key required\");\nif (namespace == null || namespace.isEmpty()) throw new IllegalArgumentException(\"namespace required\");","typeGuard":null,"tryCatchPattern":"try {\n    boolean removed = store.deleteItem(namespace, key);\n    return removed;\n} catch (RuntimeException e) {\n    logger.error(\"delete failed: {}\", e.getCause());\n    return false;\n}","preventionTips":["Validate arguments before delete","Use thread-safe backing collections","Retry transient backend failures with backoff"],"tags":["store","database","delete"],"backgroundTag":"database-write-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"}