alibaba/spring-ai-alibaba · error · RuntimeException

Failed to delete item from MongoDB-like storage

Error message

Failed to delete item from MongoDB-like storage

What it means

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.

Solutions

  1. Validate namespace/key are non-null and non-blank before deleteItem
  2. Inspect getCause() for the root exception
  3. Confirm the backing collection implementation is thread-safe
  4. If backed by real MongoDB, check connection health and retry the delete

Example fix

// before
boolean removed = store.deleteItem(ns, key); // key may be null
// after
if (key == null || key.isBlank()) {
    throw new IllegalArgumentException("key required");
}
boolean removed = store.deleteItem(ns, key);
Defensive patterns

Strategy: validation

Validate before calling

if (key == null || key.isBlank()) throw new IllegalArgumentException("key required");
if (namespace == null || namespace.isEmpty()) throw new IllegalArgumentException("namespace required");

Try / catch

try {
    boolean removed = store.deleteItem(namespace, key);
    return removed;
} catch (RuntimeException e) {
    logger.error("delete failed: {}", e.getCause());
    return false;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/7c7ae3a139d16e01. Report an issue: GitHub.

Appendix: source

Thrown at spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/MongoStore.java:134

		catch (Exception e) {
			throw new RuntimeException("Failed to retrieve item from MongoDB-like storage", e);
		}
		finally {
			lock.readLock().unlock();
		}
	}

	@Override
	public boolean deleteItem(List<String> namespace, String key) {
		validateDeleteItem(namespace, key);

		lock.writeLock().lock();
		try {
			String documentId = createDocumentId(namespace, key);
			return mongoLikeCollection.remove(documentId) != null;
		}
		catch (Exception e) {
			throw new RuntimeException("Failed to delete item from MongoDB-like storage", e);
		}
		finally {
			lock.writeLock().unlock();
		}
	}

	@Override
	public StoreSearchResult searchItems(StoreSearchRequest searchRequest) {
		validateSearchItems(searchRequest);

		lock.readLock().lock();
		try {
			List<StoreItem> allItems = getAllItems();

			// Apply filters
			List<StoreItem> filteredItems = allItems.stream()
				.filter(item -> matchesSearchCriteria(item, searchRequest))
				.collect(Collectors.toList());

View on GitHub (pinned to f82da0b50f)