Skip to content

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

@matheuscirillo

Description

@matheuscirillo

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions