MorphiaOrg / MorphiaOrg/morphia

Datastore#replace(T entity) should not throw exception when no documents are updated

Open
#3,498 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement Waiting for Response
Dominant language
Java
Stars
1.7k
Forks
449
Avg merge
7m
Merged PRs (30d)
10

Description

So I'm testing 3.0.0 SNAPSHOT and I know this is a WIP, but I would like to suggest an improvement.

First of all, It has been working great so far.

I don't actually understand why we would have to throw an error in a replace operation when no document is updated.
I would rather be able to use something like a ReplaceResult, just like the UpdateResult so I can decide if I have to throw an exception or not. It kinda breaks if I have an idempotent operation consumed by an user, for example, and I can't look to the exception type either, because it is too generic (MappingException).

When no document is updated, this error is thrown:

dev.morphia.mapping.MappingException: **No documents were updated by the operation for ID**:  0M40M2AR005YJ
	at dev.morphia.MorphiaDatastore.replace(MorphiaDatastore.java:493)

Maybe wrap the operation result within a ReplaceResult is a solution to give more control to the caller.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at MorphiaDatastore.replace(MorphiaDatastore.java:493) and compare the replace operation with the existing UpdateResult API. Review the proposed ReplaceResult approach and determine how callers should handle operations that update no documents; done means the caller can inspect the outcome without an automatic generic MappingException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb
Domain
backend-api-design, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.