Announcement Announcement Module
No announcement yet.
MongDB Delete in Repository Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:

    public class Foobar implements Serializable {
       private Long id;
       private String name; 
    A sample Repository

    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* there a way I can tell Spring this query should *delete*? Is there a better way to do this?

    thanks in advance,


  • #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.