{"record":{"id":"2b3492d489bb8f80","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-store-item-in-mongodb-like-storage","errorCode":null,"errorMessage":"Failed to store item in MongoDB-like storage","messagePattern":"Failed to store item in 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":94,"sourceCode":"\tpublic void putItem(StoreItem item) {\n\t\tvalidatePutItem(item);\n\n\t\tlock.writeLock().lock();\n\t\ttry {\n\t\t\tString documentId = createDocumentId(item.getNamespace(), item.getKey());\n\n\t\t\tMap<String, Object> doc = new HashMap<>();\n\t\t\tdoc.put(\"_id\", documentId);\n\t\t\tdoc.put(\"namespace\", item.getNamespace());\n\t\t\tdoc.put(\"key\", item.getKey());\n\t\t\tdoc.put(\"value\", item.getValue());\n\t\t\tdoc.put(\"createdAt\", item.getCreatedAt());\n\t\t\tdoc.put(\"updatedAt\", item.getUpdatedAt());\n\n\t\t\tmongoLikeCollection.put(documentId, doc);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new RuntimeException(\"Failed to store item in 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 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}","sourceCodeStart":76,"sourceCodeEnd":112,"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#L76-L112","documentation":"MongoStore.putItem serializes the StoreItem into a document map and inserts it into the in-memory mongoLikeCollection; any exception is wrapped in RuntimeException('Failed to store item in MongoDB-like storage'). It executes under the store write lock.","triggerScenarios":"store.putItem(namespace, key, value) throws — e.g. createDocumentId fails on invalid namespace/key, serialization of the value fails, or the backing collection rejects the entry.","commonSituations":"Non-serializable or cyclic objects stored as values; null/blank keys bubbling up from document-id construction; swapping MongoStore for a real MongoDB client whose connection fails inside put.","solutions":["Read getCause() to identify whether it is id-construction or serialization","Validate namespace/key and value are non-null before putItem","Ensure stored values are JSON-serializable POJOs/maps","If backed by a real MongoDB, verify connection settings and availability"],"exampleFix":"// before\nstore.putItem(ns, key, someObjectWithCycles);\n// after\nString json = objectMapper.writeValueAsString(someObjectWithCycles);\nstore.putItem(ns, key, objectMapper.readValue(json, Map.class));","handlingStrategy":"try-catch","validationCode":"if (key == null || key.isBlank()) throw new IllegalArgumentException(\"key required\");\nObjects.requireNonNull(value, \"value required\");","typeGuard":null,"tryCatchPattern":"try {\n    store.putItem(namespace, key, value);\n} catch (RuntimeException e) {\n    logger.error(\"put failed: {}\", e.getCause());\n    throw new StoreException(\"persist failed\", e);\n}","preventionTips":["Store only JSON-serializable values","Validate keys at the boundary","Verify backend connectivity before bulk writes"],"tags":["store","database","write"],"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"}