Announcement Announcement Module
Collapse
No announcement yet.
MongDB Delete in Repository Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MongDB Delete in Repository

    Hello all, I'm using the latest version of MongoDB *with* Repositories and trying to do something like "delete by $field". For example:

    A sample bean:

    Code:
    @Document
    public class Foobar implements Serializable {
    
        @Id
       private Long id;
    
       private String name; 
    }
    A sample Repository

    Code:
    @Document
    public interface FoobarRepository extends MongoRepository<Foobar, Long>{
    
        void deleteByName(final String name);
    }
    All methods inherited from MongoRepository work well...but this one that I tried to define in the interface makes Spring Data barf. Essentially, Spring Data's repository generator thinks "delete" is a field in Foobar....when in actuality, its a*verb*.

    I know there is a @Query annotation I can use...but it seems to only support JSON queries...but isn't that only for *searching* and not *deleting*...is there a way I can tell Spring this query should *delete*? Is there a better way to do this?

    thanks in advance,

    /m

  • #2
    The query methods currently only support reading data. To delete entities in combination with predicates have a look at the reference documentation about how to add custom implementations for single methods.

    Comment

    Working...
    X